Skip to content

Commit

Permalink
enh(bash) default value is another variable
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Feb 29, 2020
1 parent efdaf03 commit bb8f04f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -17,6 +17,7 @@ Core Changes:

Language Improvements:

- enh(bash) default value is another variable (#2439) [Josh Goebel][]
- enh(bash) string nested within string (#2439) [Josh Goebel][]
- enh(bash) Add arithmetic expression support (#2439) [Josh Goebel][]
- enh(clojure) Add support for global definitions name (#2347) [Alexandre Grison][]
Expand Down
14 changes: 11 additions & 3 deletions src/languages/bash.js
Expand Up @@ -7,13 +7,21 @@ Category: common
*/

export default function(hljs) {
const VAR = {
const VAR = {};
const BRACKET_VAR = {
begin: /\$\{/, end:/\}/,
contains: [
{ begin: /:-/, contains: [VAR] } // default values
]
};
Object.assign(VAR,{
className: 'variable',
variants: [
{begin: /\$[\w\d#@][\w\d_]*/},
{begin: /\$\{(.*?)}/}
BRACKET_VAR
]
};
});

const SUBST = {
className: 'subst',
begin: /\$\(/, end: /\)/,
Expand Down
3 changes: 3 additions & 0 deletions test/markup/bash/variables.expect.txt
@@ -0,0 +1,3 @@
<span class="hljs-variable">$A</span>
<span class="hljs-variable">${B}</span>
<span class="hljs-variable">${WURST:-<span class="hljs-variable">${CARNE}</span>}</span>
3 changes: 3 additions & 0 deletions test/markup/bash/variables.txt
@@ -0,0 +1,3 @@
$A
${B}
${WURST:-${CARNE}}

0 comments on commit bb8f04f

Please sign in to comment.