aboutsummaryrefslogtreecommitdiffstats
path: root/public/prism/prism-t4-templating.js
blob: dc8a412af92fb5bf296e40efa2bfe0a7747b1b20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(function (Prism) {
  function createBlock(prefix, inside, contentAlias) {
    return {
      pattern: RegExp('<#' + prefix + '[\\s\\S]*?#>'),
      alias: 'block',
      inside: {
        delimiter: {
          pattern: RegExp('^<#' + prefix + '|#>$'),
          alias: 'important',
        },
        content: {
          pattern: /[\s\S]+/,
          inside: inside,
          alias: contentAlias,
        },
      },
    };
  }

  function createT4(insideLang) {
    var grammar = Prism.languages[insideLang];
    var className = 'language-' + insideLang;

    return {
      block: {
        pattern: /<#[\s\S]+?#>/,
        inside: {
          directive: createBlock('@', {
            'attr-value': {
              pattern: /=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+)/,
              inside: {
                punctuation: /^=|^["']|["']$/,
              },
            },
            keyword: /\b\w+(?=\s)/,
            'attr-name': /\b\w+/,
          }),
          expression: createBlock('=', grammar, className),
          'class-feature': createBlock('\\+', grammar, className),
          standard: createBlock('', grammar, className),
        },
      },
    };
  }

  Prism.languages['t4-templating'] = Object.defineProperty({}, 'createT4', {
    value: createT4,
  });
})(Prism);