Skip to content

Commit cda976b

Browse files
Shell sessions: Fixed multi-line commands (#2872)
1 parent a9a199b commit cda976b

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

components/prism-shell-session.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616

1717
Prism.languages['shell-session'] = {
1818
'command': {
19-
pattern: RegExp(/^(?:[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?::[^\0-\x1F$#*?"<>:;|]+)?|[^\0-\x1F$#*?"<>:;|]+)?[$#](?:[^\\\r\n'"<$]|\\.|\$(?!')|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }), 'm'),
19+
pattern: RegExp(
20+
// user info
21+
/^(?:[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?::[^\0-\x1F$#*?"<>:;|]+)?|[^\0-\x1F$#*?"<>:;|]+)?/.source +
22+
// shell symbol
23+
/[$#]/.source +
24+
// bash command
25+
/(?:[^\\\r\n'"<$]|\\(?:[^\r]|\r\n?)|\$(?!')|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }),
26+
'm'
27+
),
2028
greedy: true,
2129
inside: {
2230
'info': {

components/prism-shell-session.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
fyu@home $ sudo ls -l ~/.config 's' && \
2+
echo 'hello'
3+
drwxr-xr-x - franklinyu 26 Sep 2020 asciinema
4+
drwxr-xr-x - franklinyu 26 Jan 2020 'bash'
5+
hello
6+
7+
----------------------------------------------------
8+
9+
[
10+
["command", [
11+
["info", [
12+
["user", "fyu@home"],
13+
["path", " "]
14+
]],
15+
["shell-symbol", "$"],
16+
["bash", [
17+
["function", "sudo"],
18+
["function", "ls"],
19+
" -l ~/.config ",
20+
["string", "'s'"],
21+
["operator", ["&&"]],
22+
["punctuation", "\\"],
23+
24+
["builtin", "echo"],
25+
["string", "'hello'"]
26+
]]
27+
]],
28+
29+
["output", "drwxr-xr-x - franklinyu 26 Sep 2020 asciinema\r\ndrwxr-xr-x - franklinyu 26 Jan 2020 'bash'\r\nhello"]
30+
]

0 commit comments

Comments
 (0)