Skip to content

Commit

Permalink
Bash: Add support for quoted command substitution. Fix #1287
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Mar 3, 2018
1 parent de8ebe2 commit 63fc215
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion components/prism-bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// Command Substitution
{
pattern: /\$\([^)]+\)|`[^`]+`/,
greedy: true,
inside: {
variable: /^\$\(|^`|\)$|`$/
}
Expand All @@ -48,7 +49,7 @@
inside: insideString
},
{
pattern: /(["'])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
pattern: /(["'])(?:\\[\s\S]|\$\([^)]+\)|`[^`]+`|(?!\1)[^\\])*\1/,
greedy: true,
inside: insideString
}
Expand All @@ -72,6 +73,7 @@
};

var inside = insideString.variable[1].inside;
inside.string = Prism.languages.bash.string;
inside['function'] = Prism.languages.bash['function'];
inside.keyword = Prism.languages.bash.keyword;
inside.boolean = Prism.languages.bash.boolean;
Expand Down
2 changes: 1 addition & 1 deletion components/prism-bash.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 17 additions & 6 deletions tests/languages/bash/command_substitution_feature.test
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
$(echo foo)
`echo foo`
"$(echo foo) bar"
$(echo "foo")
`echo "foo"`
"$(echo "foo") bar"
"`echo "foo"` bar"

----------------------------------------------------

[
["variable", [
["variable", "$("],
["keyword", "echo"],
" foo",
["string", ["\"foo\""]],
["variable", ")"]
]],
["variable", [
["variable", "`"],
["keyword", "echo"],
" foo",
["string", ["\"foo\""]],
["variable", "`"]
]],
["string", [
"\"",
["variable", [
["variable", "$("],
["keyword", "echo"],
" foo",
["string", ["\"foo\""]],
["variable", ")"]
]],
" bar\""
]],
["string", [
"\"",
["variable", [
["variable", "`"],
["keyword", "echo"],
["string", ["\"foo\""]],
["variable", "`"]
]],
" bar\""
]]
]

Expand Down

0 comments on commit 63fc215

Please sign in to comment.