summaryrefslogtreecommitdiffstats
path: root/public/prism/prism-velocity.js
blob: 0799e791bfc8edee54609b913b43ca8b2a124daf (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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Ou
(function (Prism) {
  Prism.languages.velocity = Prism.languages.extend('markup', {});

  var velocity = {
    variable: {
      pattern:
        /(^|[^\\](?:\\\\)*)\$!?(?:[a-z][\w-]*(?:\([^)]*\))?(?:\.[a-z][\w-]*(?:\([^)]*\))?|\[[^\]]+\])*|\{[^}]+\})/i,
      lookbehind: true,
      inside: {}, // See below
    },
    string: {
      pattern: /"[^"]*"|'[^']*'/,
      greedy: true,
    },
    number: /\b\d+\b/,
    boolean: /\b(?:false|true)\b/,
    operator: /[=!<>]=?|[+*/%-]|&&|\|\||\.\.|\b(?:eq|g[et]|l[et]|n(?:e|ot))\b/,
    punctuation: /[(){}[\]:,.]/,
  };

  velocity.variable.inside = {
    string: velocity['string'],
    function: {
      pattern: /([^\w-])[a-z][\w-]*(?=\()/,
      lookbehind: true,
    },
    number: velocity['number'],
    boolean: velocity['boolean'],
    punctuation: velocity['punctuation'],
  };

  Prism.languages.insertBefore('velocity', 'comment', {
    unparsed: {
      pattern: /(^|[^\\])#\[\[[\s\S]*?\]\]#/,
      lookbehind: true,
      greedy: true,
      inside: {
        punctuation: /^#\[\[|\]\]#$/,
      },
    },
    'velocity-comment': [
      {
        pattern: /(^|[^\\])#\*[\s\S]*?\*#/,
        lookbehind: true,
        greedy: true,
        alias: 'comment',
      },
      {
        pattern: /(^|[^\\])##.*/,
        lookbehind: true,
        greedy: true,
        alias: 'comment',
      },
    ],
    directive: {
      pattern:
        /(^|[^\\](?:\\\\)*)#@?(?:[a-z][\w-]*|\{[a-z][\w-]*\})(?:\s*\((?:[^()]|\([^()]*\))*\))?/i,
      lookbehind: true,
      inside: {
        keyword: {
          pattern: /^#@?(?:[a-z][\w-]*|\{[a-z][\w-]*\})|\bin\b/,
          inside: {
            punctuation: /[{}]/,
          },
        },
        rest: velocity,
      },
    },
    variable: velocity['variable'],
  });

  Prism.languages.velocity['tag'].inside['attr-value'].inside.rest =
    Prism.languages.velocity;
})(Prism);