UNPKG

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