forked from PrismJS/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prism-shell-session.js
52 lines (46 loc) · 1.23 KB
/
prism-shell-session.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(function (Prism) {
// CAREFUL!
// The following patterns are concatenated, so the group referenced by a back reference is non-obvious!
var strings = [
// normal string
// 1 capturing group
/(["'])(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|(?!\1)[^\\`$])*\1/.source,
// here doc
// 2 capturing groups
/<<-?\s*(["']?)(\w+)\2\s[\s\S]*?[\r\n]\3/.source
].join('|');
Prism.languages['shell-session'] = {
'info': {
// foo@bar:~/files$ exit
// foo@bar$ exit
pattern: /^[^\r\n$#*!]+(?=[$#])/m,
alias: 'punctuation',
inside: {
'path': {
pattern: /(:)[\s\S]+/,
lookbehind: true
},
'user': /^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?=:|$)/,
'punctuation': /:/
}
},
'command': {
pattern: RegExp(/[$#](?:[^\\\r\n'"<]|\\.|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; })),
greedy: true,
inside: {
'bash': {
pattern: /(^[$#]\s*)[\s\S]+/,
lookbehind: true,
alias: 'language-bash',
inside: Prism.languages.bash
},
'shell-symbol': {
pattern: /^[$#]/,
alias: 'important'
}
}
},
'output': /.(?:.*(?:[\r\n]|.$))*/
};
Prism.languages['sh-session'] = Prism.languages['shellsession'] = Prism.languages['shell-session'];
}(Prism));