1 | Prism.languages.javascript = Prism.languages.extend('clike', {
|
2 | 'keyword': /\b(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/,
|
3 | 'number': /\b(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,
|
4 |
|
5 | 'function': /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*\()/i,
|
6 | 'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/
|
7 | });
|
8 |
|
9 | Prism.languages.insertBefore('javascript', 'keyword', {
|
10 | 'regex': {
|
11 | pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(\[[^\]\r\n]+]|\\.|[^/\\\[\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})\]]))/,
|
12 | lookbehind: true,
|
13 | greedy: true
|
14 | },
|
15 |
|
16 | 'function-variable': {
|
17 | pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i,
|
18 | alias: 'function'
|
19 | },
|
20 | 'constant': /\b[A-Z][A-Z\d_]*\b/
|
21 | });
|
22 |
|
23 | Prism.languages.insertBefore('javascript', 'string', {
|
24 | 'template-string': {
|
25 | pattern: /`(?:\\[\s\S]|\${[^}]+}|[^\\`])*`/,
|
26 | greedy: true,
|
27 | inside: {
|
28 | 'interpolation': {
|
29 | pattern: /\${[^}]+}/,
|
30 | inside: {
|
31 | 'interpolation-punctuation': {
|
32 | pattern: /^\${|}$/,
|
33 | alias: 'punctuation'
|
34 | },
|
35 | rest: null
|
36 | }
|
37 | },
|
38 | 'string': /[\s\S]+/
|
39 | }
|
40 | }
|
41 | });
|
42 | Prism.languages.javascript['template-string'].inside['interpolation'].inside.rest = Prism.languages.javascript;
|
43 |
|
44 | if (Prism.languages.markup) {
|
45 | Prism.languages.insertBefore('markup', 'tag', {
|
46 | 'script': {
|
47 | pattern: /(<script[\s\S]*?>)[\s\S]*?(?=<\/script>)/i,
|
48 | lookbehind: true,
|
49 | inside: Prism.languages.javascript,
|
50 | alias: 'language-javascript',
|
51 | greedy: true
|
52 | }
|
53 | });
|
54 | }
|
55 |
|
56 | Prism.languages.js = Prism.languages.javascript;
|