diff --git a/CHANGES.md b/CHANGES.md index e5197e6b04..afdeb16cd9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,6 +23,7 @@ New Languages: Language Improvements: +- enh(shell) Recognize prompts which contain tilde `~` (#2859) [Guillaume Grossetie][] - enh(shell) Add support for multiline commands with line continuation `\` (#2861) [Guillaume Grossetie][] - enh(autodetect) Over 30+ improvements to auto-detect (#2745) [Josh Goebel][] - 4-5% improvement in auto-detect against large sample set diff --git a/src/languages/shell.js b/src/languages/shell.js index 7e833ee768..2c713da19d 100644 --- a/src/languages/shell.js +++ b/src/languages/shell.js @@ -14,7 +14,10 @@ export default function(hljs) { contains: [ { className: 'meta', - begin: /^\s{0,3}[/\w\d[\]()@-]*[>%$#]/, + // We cannot add \s (spaces) in the regular expression otherwise it will be too broad and produce unexpected result. + // For instance, in the following example, it would match "echo /path/to/home >" as a prompt: + // echo /path/to/home > t.exe + begin: /^\s{0,3}[/~\w\d[\]()@-]*[>%$#]/, starts: { end: /[^\\](?=\s*$)/, subLanguage: 'bash' diff --git a/test/markup/shell/prompt-with-tilde.expected.txt b/test/markup/shell/prompt-with-tilde.expected.txt new file mode 100644 index 0000000000..57af2ff5de --- /dev/null +++ b/test/markup/shell/prompt-with-tilde.expected.txt @@ -0,0 +1,4 @@ +~/docs> cat readme.adoc += Highlight.js + +Highlight.js is a syntax highlighter written in JavaScript. diff --git a/test/markup/shell/prompt-with-tilde.txt b/test/markup/shell/prompt-with-tilde.txt new file mode 100644 index 0000000000..ddbfcf84e3 --- /dev/null +++ b/test/markup/shell/prompt-with-tilde.txt @@ -0,0 +1,4 @@ +~/docs> cat readme.adoc += Highlight.js + +Highlight.js is a syntax highlighter written in JavaScript.