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 // 1 capturing group
13 /<<-?\s*(\w+?)[ \t]*(?!.)[\s\S]*?[\r\n]\2/.source,
14
15 // here doc quoted
16 // 2 capturing group
17 /<<-?\s*(["'])(\w+)\3[ \t]*(?!.)[\s\S]*?[\r\n]\4/.source
18 ].join('|');
19
20 Prism.languages['shell-session'] = {
21 'info': {
22 // foo@bar:~/files$ exit
23 // foo@bar$ exit
24 pattern: /^[^\r\n$#*!]+(?=[$#])/m,
25 alias: 'punctuation',
26 inside: {
27 'path': {
28 pattern: /(:)[\s\S]+/,
29 lookbehind: true
30 },
31 'user': /^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?=:|$)/,
32 'punctuation': /:/
33 }
34 },
35 'command': {
36 pattern: RegExp(/[$#](?:[^\\\r\n'"<]|\\.|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; })),
37 greedy: true,
38 inside: {
39 'bash': {
40 pattern: /(^[$#]\s*)[\s\S]+/,
41 lookbehind: true,
42 alias: 'language-bash',
43 inside: Prism.languages.bash
44 },
45 'shell-symbol': {
46 pattern: /^[$#]/,
47 alias: 'important'
48 }
49 }
50 },
51 'output': /.(?:.*(?:[\r\n]|.$))*/
52 };
53
54}(Prism));