summaryrefslogtreecommitdiffstats
path: root/public/prism/prism-nginx.js
blob: b43e77065dfa164b6b8a85bfa3acc1697f5330bf (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
50
51
52
53
54
55
(function (Prism) {
  var variable =
    /\$(?:\w[a-z\d]*(?:_[^\x00-\x1F\s"'\\()$]*)?|\{[^}\s"'\\]+\})/i;

  Prism.languages.nginx = {
    comment: {
      pattern: /(^|[\s{};])#.*/,
      lookbehind: true,
      greedy: true,
    },
    directive: {
      pattern:
        /(^|\s)\w(?:[^;{}"'\\\s]|\\.|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\s+(?:#.*(?!.)|(?![#\s])))*?(?=\s*[;{])/,
      lookbehind: true,
      greedy: true,
      inside: {
        string: {
          pattern:
            /((?:^|[^\\])(?:\\\\)*)(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/,
          lookbehind: true,
          greedy: true,
          inside: {
            escape: {
              pattern: /\\["'\\nrt]/,
              alias: 'entity',
            },
            variable: variable,
          },
        },
        comment: {
          pattern: /(\s)#.*/,
          lookbehind: true,
          greedy: true,
        },
        keyword: {
          pattern: /^\S+/,
          greedy: true,
        },

        // other patterns

        boolean: {
          pattern: /(\s)(?:off|on)(?!\S)/,
          lookbehind: true,
        },
        number: {
          pattern: /(\s)\d+[a-z]*(?!\S)/i,
          lookbehind: true,
        },
        variable: variable,
      },
    },
    punctuation: /[{};]/,
  };
})(Prism);