Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(shell) recognize prompt that contain tilde(s) #2859

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.