main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.7 KB
|
Rev | Line | |
---|
[d24f17c] | 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 | /"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/.source,
|
---|
| 9 | /'[^']*'/.source,
|
---|
| 10 | /\$'(?:[^'\\]|\\[\s\S])*'/.source,
|
---|
| 11 |
|
---|
| 12 | // here doc
|
---|
| 13 | // 2 capturing groups
|
---|
| 14 | /<<-?\s*(["']?)(\w+)\1\s[\s\S]*?[\r\n]\2/.source
|
---|
| 15 | ].join('|');
|
---|
| 16 |
|
---|
| 17 | Prism.languages['shell-session'] = {
|
---|
| 18 | 'command': {
|
---|
| 19 | pattern: RegExp(
|
---|
| 20 | // user info
|
---|
| 21 | /^/.source +
|
---|
| 22 | '(?:' +
|
---|
| 23 | (
|
---|
| 24 | // <user> ":" ( <path> )?
|
---|
| 25 | /[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+(?::[^\0-\x1F$#%*?"<>:;|]+)?/.source +
|
---|
| 26 | '|' +
|
---|
| 27 | // <path>
|
---|
| 28 | // Since the path pattern is quite general, we will require it to start with a special character to
|
---|
| 29 | // prevent false positives.
|
---|
| 30 | /[/~.][^\0-\x1F$#%*?"<>@:;|]*/.source
|
---|
| 31 | ) +
|
---|
| 32 | ')?' +
|
---|
| 33 | // shell symbol
|
---|
| 34 | /[$#%](?=\s)/.source +
|
---|
| 35 | // bash command
|
---|
| 36 | /(?:[^\\\r\n \t'"<$]|[ \t](?:(?!#)|#.*$)|\\(?:[^\r]|\r\n?)|\$(?!')|<(?!<)|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }),
|
---|
| 37 | 'm'
|
---|
| 38 | ),
|
---|
| 39 | greedy: true,
|
---|
| 40 | inside: {
|
---|
| 41 | 'info': {
|
---|
| 42 | // foo@bar:~/files$ exit
|
---|
| 43 | // foo@bar$ exit
|
---|
| 44 | // ~/files$ exit
|
---|
| 45 | pattern: /^[^#$%]+/,
|
---|
| 46 | alias: 'punctuation',
|
---|
| 47 | inside: {
|
---|
| 48 | 'user': /^[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+/,
|
---|
| 49 | 'punctuation': /:/,
|
---|
| 50 | 'path': /[\s\S]+/
|
---|
| 51 | }
|
---|
| 52 | },
|
---|
| 53 | 'bash': {
|
---|
| 54 | pattern: /(^[$#%]\s*)\S[\s\S]*/,
|
---|
| 55 | lookbehind: true,
|
---|
| 56 | alias: 'language-bash',
|
---|
| 57 | inside: Prism.languages.bash
|
---|
| 58 | },
|
---|
| 59 | 'shell-symbol': {
|
---|
| 60 | pattern: /^[$#%]/,
|
---|
| 61 | alias: 'important'
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | },
|
---|
| 65 | 'output': /.(?:.*(?:[\r\n]|.$))*/
|
---|
| 66 | };
|
---|
| 67 |
|
---|
| 68 | Prism.languages['sh-session'] = Prism.languages['shellsession'] = Prism.languages['shell-session'];
|
---|
| 69 |
|
---|
| 70 | }(Prism));
|
---|
Note:
See
TracBrowser
for help on using the repository browser.