diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2019-02-17 21:53:36 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2019-02-17 21:53:36 +0100 |
| commit | 8e9ef5ba62b8bee028428384ad5666e245eb854c (patch) | |
| tree | b382c5b40f122b2a152da2226006abab34abe105 /source/languages/prism-javascript.js | |
| parent | ad974810d43e1d5f70bca269665c25230e6a3221 (diff) | |
| download | mitjafelicijan.com-8e9ef5ba62b8bee028428384ad5666e245eb854c.tar.gz | |
content update
Diffstat (limited to 'source/languages/prism-javascript.js')
| -rw-r--r-- | source/languages/prism-javascript.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/source/languages/prism-javascript.js b/source/languages/prism-javascript.js new file mode 100644 index 0000000..7800a7d --- /dev/null +++ b/source/languages/prism-javascript.js | |||
| @@ -0,0 +1,56 @@ | |||
| 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 | // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444) | ||
| 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 | // This must be declared before keyword because we use "function" inside the look-forward | ||
| 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 // See below | ||
| 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; | ||
