diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-30 19:47:21 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-30 19:47:21 +0100 |
| commit | a98b5ea6fe8e8cc98a55e0fd793e6e8660ea31c1 (patch) | |
| tree | 542810ab5aef99150db228bb54fd58303dcb31c7 /public/prism/prism-tt2.js | |
| parent | ab355897a12b7bda1089a44de326d41455a0f7a3 (diff) | |
chore: add prismjs for syntax highlighting
Diffstat (limited to 'public/prism/prism-tt2.js')
| -rw-r--r-- | public/prism/prism-tt2.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/public/prism/prism-tt2.js b/public/prism/prism-tt2.js new file mode 100644 index 0000000..f550bf9 --- /dev/null +++ b/public/prism/prism-tt2.js @@ -0,0 +1,56 @@ +(function (Prism) { + Prism.languages.tt2 = Prism.languages.extend('clike', { + comment: /#.*|\[%#[\s\S]*?%\]/, + keyword: + /\b(?:BLOCK|CALL|CASE|CATCH|CLEAR|DEBUG|DEFAULT|ELSE|ELSIF|END|FILTER|FINAL|FOREACH|GET|IF|IN|INCLUDE|INSERT|LAST|MACRO|META|NEXT|PERL|PROCESS|RAWPERL|RETURN|SET|STOP|SWITCH|TAGS|THROW|TRY|UNLESS|USE|WHILE|WRAPPER)\b/, + punctuation: /[[\]{},()]/, + }); + + Prism.languages.insertBefore('tt2', 'number', { + operator: /=[>=]?|!=?|<=?|>=?|&&|\|\|?|\b(?:and|not|or)\b/, + variable: { + pattern: /\b[a-z]\w*(?:\s*\.\s*(?:\d+|\$?[a-z]\w*))*\b/i, + }, + }); + + Prism.languages.insertBefore('tt2', 'keyword', { + delimiter: { + pattern: /^(?:\[%|%%)-?|-?%\]$/, + alias: 'punctuation', + }, + }); + + Prism.languages.insertBefore('tt2', 'string', { + 'single-quoted-string': { + pattern: /'[^\\']*(?:\\[\s\S][^\\']*)*'/, + greedy: true, + alias: 'string', + }, + 'double-quoted-string': { + pattern: /"[^\\"]*(?:\\[\s\S][^\\"]*)*"/, + greedy: true, + alias: 'string', + inside: { + variable: { + pattern: /\$(?:[a-z]\w*(?:\.(?:\d+|\$?[a-z]\w*))*)/i, + }, + }, + }, + }); + + // The different types of TT2 strings "replace" the C-like standard string + delete Prism.languages.tt2.string; + + Prism.hooks.add('before-tokenize', function (env) { + var tt2Pattern = /\[%[\s\S]+?%\]/g; + Prism.languages['markup-templating'].buildPlaceholders( + env, + 'tt2', + tt2Pattern + ); + }); + + Prism.hooks.add('after-tokenize', function (env) { + Prism.languages['markup-templating'].tokenizePlaceholders(env, 'tt2'); + }); +})(Prism); |
