Skip to content

Commit

Permalink
enh(shell) recognize prompts that contain tilde(s) (#2859)
Browse files Browse the repository at this point in the history
Resolves #2858.
  • Loading branch information
ggrossetie committed Nov 15, 2020
1 parent c36d5ae commit 4fed71d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/languages/shell.js
Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions test/markup/shell/prompt-with-tilde.expected.txt
@@ -0,0 +1,4 @@
<span class="hljs-meta">~/docs&gt;</span><span class="bash"> cat readme.adoc</span>
= Highlight.js

Highlight.js is a syntax highlighter written in JavaScript.
4 changes: 4 additions & 0 deletions 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.

0 comments on commit 4fed71d

Please sign in to comment.