Skip to content

Commit

Permalink
enh(shell) recognize prompts that contain tilde(s)
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 acf0527
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 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 Expand Up @@ -83,7 +84,6 @@ New themes:
[Marcus Ortiz]: https://github.com/mportiz08
[Paul Reid]: https://github.com/RedGuy12


## Version 10.3.1

Prior version let some look-behind regex sneak in, which does not work
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 acf0527

Please sign in to comment.