Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ New Grammars:

Core Grammars:

- fix(bash) keep heredoc continuation commands outside the string span, issue #4377 [puneetdixit200][]
- fix(javascript) correctly highlight 'for await' again [wolfgang42][]
- enh(csp) add missing directives / keywords from MDN (7 more) [Max Liashuk][]
- enh(ada) add new `parallel` keyword, allow `[]` for Ada 2022 [Max Reznik][]
Expand Down Expand Up @@ -55,6 +56,7 @@ CONTRIBUTORS
[te-ing]: https://github.com/te-ing
[Anthony Martin]: https://github.com/anthony-c-martin
[NriotHrreion]: https://github.com/NriotHrreion
[puneetdixit200]: https://github.com/puneetdixit200


## Version 11.11.1
Expand Down
71 changes: 47 additions & 24 deletions src/languages/bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ export default function(hljs) {
}
}
);
const HERE_DOC = {
begin: /<<-?\s*(?=\w+)/,
starts: { contains: [
hljs.END_SAME_AS_BEGIN({
begin: /(\w+)/,
end: /(\w+)/,
className: 'string'
})
] }
};
const QUOTE_STRING = {
className: 'string',
begin: /"/,
Expand Down Expand Up @@ -368,27 +358,60 @@ export default function(hljs) {
"whoami",
"yes"
];
const BASH_KEYWORDS = {
$pattern: /\b[a-z][a-z0-9._-]+\b/,
keyword: KEYWORDS,
literal: LITERALS,
built_in: [
...SHELL_BUILT_INS,
...BASH_BUILT_INS,
// Shell modifiers
"set",
"shopt",
...ZSH_BUILT_INS,
...GNU_CORE_UTILS
]
};
let heredocDelimiter = "";
const HERE_DOC_BODY = {
className: 'string',
begin: /\n/,
end: /^\t*(\w+)$/m,
endsParent: true,
'on:end': (m, resp) => {
if (m[1] !== heredocDelimiter) resp.ignoreMatch();
}
};
const HERE_DOC = {
begin: /<<-?\s*(\w+)/,
'on:begin': (m) => { heredocDelimiter = m[1]; },
end: /\n/,
returnEnd: true,
keywords: BASH_KEYWORDS,
contains: [
ARITHMETIC,
COMMENT,
PATH_MODE,
QUOTE_STRING,
ESCAPED_QUOTE,
APOS_STRING,
ESCAPED_APOS,
VAR
],
starts: {
contains: [
HERE_DOC_BODY
]
}
};

return {
name: 'Bash',
aliases: [
'sh',
'zsh'
],
keywords: {
$pattern: /\b[a-z][a-z0-9._-]+\b/,
keyword: KEYWORDS,
literal: LITERALS,
built_in: [
...SHELL_BUILT_INS,
...BASH_BUILT_INS,
// Shell modifiers
"set",
"shopt",
...ZSH_BUILT_INS,
...GNU_CORE_UTILS
]
},
keywords: BASH_KEYWORDS,
contains: [
KNOWN_SHEBANG, // to catch known shells and boost relevancy
hljs.SHEBANG(), // to catch unknown shells but still highlight the shebang
Expand Down
3 changes: 3 additions & 0 deletions test/markup/bash/heredoc-continuation.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="hljs-built_in">echo</span> <span class="hljs-string">&quot;ok&quot;</span> &lt;&lt;-EOF | <span class="hljs-built_in">cat</span><span class="hljs-string">
Hello
EOF</span>
3 changes: 3 additions & 0 deletions test/markup/bash/heredoc-continuation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
echo "ok" <<-EOF | cat
Hello
EOF
2 changes: 1 addition & 1 deletion test/markup/bash/strings.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SCRIPT_DIR=<span class="hljs-string">&quot;<span class="hljs-subst">$( cd <span
TLS_DIR=<span class="hljs-string">&quot;<span class="hljs-variable">$SCRIPT_DIR</span>/../src/main/resources/tls&quot;</span>
ROOT_DIR=<span class="hljs-string">&quot;<span class="hljs-variable">$SCRIPT_DIR</span>/..&quot;</span>

jshell -s - &lt;&lt; <span class="hljs-string">EOF
jshell -s - &lt;&lt; EOF<span class="hljs-string">
System.out.printf(&quot;Procs: %s%n&quot;, getdata())
EOF</span>

Expand Down