1 | (function (Prism) {
|
---|
2 |
|
---|
3 | Prism.languages.tt2 = Prism.languages.extend('clike', {
|
---|
4 | 'comment': /#.*|\[%#[\s\S]*?%\]/,
|
---|
5 | '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/,
|
---|
6 | 'punctuation': /[[\]{},()]/
|
---|
7 | });
|
---|
8 |
|
---|
9 | Prism.languages.insertBefore('tt2', 'number', {
|
---|
10 | 'operator': /=[>=]?|!=?|<=?|>=?|&&|\|\|?|\b(?:and|not|or)\b/,
|
---|
11 | 'variable': {
|
---|
12 | pattern: /\b[a-z]\w*(?:\s*\.\s*(?:\d+|\$?[a-z]\w*))*\b/i
|
---|
13 | }
|
---|
14 | });
|
---|
15 |
|
---|
16 | Prism.languages.insertBefore('tt2', 'keyword', {
|
---|
17 | 'delimiter': {
|
---|
18 | pattern: /^(?:\[%|%%)-?|-?%\]$/,
|
---|
19 | alias: 'punctuation'
|
---|
20 | }
|
---|
21 | });
|
---|
22 |
|
---|
23 | Prism.languages.insertBefore('tt2', 'string', {
|
---|
24 | 'single-quoted-string': {
|
---|
25 | pattern: /'[^\\']*(?:\\[\s\S][^\\']*)*'/,
|
---|
26 | greedy: true,
|
---|
27 | alias: 'string'
|
---|
28 | },
|
---|
29 | 'double-quoted-string': {
|
---|
30 | pattern: /"[^\\"]*(?:\\[\s\S][^\\"]*)*"/,
|
---|
31 | greedy: true,
|
---|
32 | alias: 'string',
|
---|
33 | inside: {
|
---|
34 | 'variable': {
|
---|
35 | pattern: /\$(?:[a-z]\w*(?:\.(?:\d+|\$?[a-z]\w*))*)/i
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
39 | });
|
---|
40 |
|
---|
41 | // The different types of TT2 strings "replace" the C-like standard string
|
---|
42 | delete Prism.languages.tt2.string;
|
---|
43 |
|
---|
44 | Prism.hooks.add('before-tokenize', function (env) {
|
---|
45 | var tt2Pattern = /\[%[\s\S]+?%\]/g;
|
---|
46 | Prism.languages['markup-templating'].buildPlaceholders(env, 'tt2', tt2Pattern);
|
---|
47 | });
|
---|
48 |
|
---|
49 | Prism.hooks.add('after-tokenize', function (env) {
|
---|
50 | Prism.languages['markup-templating'].tokenizePlaceholders(env, 'tt2');
|
---|
51 | });
|
---|
52 |
|
---|
53 | }(Prism));
|
---|