Skip to content

Commit

Permalink
Shell sessions: Fixed multi-line commands (#2872)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed May 4, 2021
1 parent a9a199b commit cda976b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
10 changes: 9 additions & 1 deletion components/prism-shell-session.js
Expand Up @@ -16,7 +16,15 @@

Prism.languages['shell-session'] = {
'command': {
pattern: RegExp(/^(?:[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?::[^\0-\x1F$#*?"<>:;|]+)?|[^\0-\x1F$#*?"<>:;|]+)?[$#](?:[^\\\r\n'"<$]|\\.|\$(?!')|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }), 'm'),
pattern: RegExp(
// user info
/^(?:[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?::[^\0-\x1F$#*?"<>:;|]+)?|[^\0-\x1F$#*?"<>:;|]+)?/.source +
// shell symbol
/[$#]/.source +
// bash command
/(?:[^\\\r\n'"<$]|\\(?:[^\r]|\r\n?)|\$(?!')|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }),
'm'
),
greedy: true,
inside: {
'info': {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-shell-session.min.js

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

30 changes: 30 additions & 0 deletions tests/languages/shell-session/issue2871.test
@@ -0,0 +1,30 @@
fyu@home $ sudo ls -l ~/.config 's' && \
echo 'hello'
drwxr-xr-x - franklinyu 26 Sep 2020 asciinema
drwxr-xr-x - franklinyu 26 Jan 2020 'bash'
hello

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

[
["command", [
["info", [
["user", "fyu@home"],
["path", " "]
]],
["shell-symbol", "$"],
["bash", [
["function", "sudo"],
["function", "ls"],
" -l ~/.config ",
["string", "'s'"],
["operator", ["&&"]],
["punctuation", "\\"],

["builtin", "echo"],
["string", "'hello'"]
]]
]],

["output", "drwxr-xr-x - franklinyu 26 Sep 2020 asciinema\r\ndrwxr-xr-x - franklinyu 26 Jan 2020 'bash'\r\nhello"]
]

0 comments on commit cda976b

Please sign in to comment.