summaryrefslogtreecommitdiff
path: root/htroot/js/languages/nestedtext.js
blob: c4c59a70f3fdb3bc461f44fe00c17e1574ecf814 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*! `nestedtext` grammar compiled for Highlight.js 11.11.1 */
  (function(){
    var hljsGrammar = (function () {
  'use strict';

  /*
  Language: NestedText
  Description: NestedText is a file format for holding data that is to be entered, edited, or viewed by people.
  Website: https://nestedtext.org/
  Category: config
  */

  /** @type LanguageFn */
  function nestedtext(hljs) {
    const NESTED = {
      match: [
        /^\s*(?=\S)/, // have to look forward here to avoid polynomial backtracking
        /[^:]+/,
        /:\s*/,
        /$/
      ],
      className: {
        2: "attribute",
        3: "punctuation"
      }
    };
    const DICTIONARY_ITEM = {
      match: [
        /^\s*(?=\S)/, // have to look forward here to avoid polynomial backtracking
        /[^:]*[^: ]/,
        /[ ]*:/,
        /[ ]/,
        /.*$/
      ],
      className: {
        2: "attribute",
        3: "punctuation",
        5: "string"
      }
    };
    const STRING = {
      match: [
        /^\s*/,
        />/,
        /[ ]/,
        /.*$/
      ],
      className: {
        2: "punctuation",
        4: "string"
      }
    };
    const LIST_ITEM = {
      variants: [
        { match: [
          /^\s*/,
          /-/,
          /[ ]/,
          /.*$/
        ] },
        { match: [
          /^\s*/,
          /-$/
        ] }
      ],
      className: {
        2: "bullet",
        4: "string"
      }
    };

    return {
      name: 'Nested Text',
      aliases: [ 'nt' ],
      contains: [
        hljs.inherit(hljs.HASH_COMMENT_MODE, {
          begin: /^\s*(?=#)/,
          excludeBegin: true
        }),
        LIST_ITEM,
        STRING,
        NESTED,
        DICTIONARY_ITEM
      ]
    };
  }

  return nestedtext;

})();

    hljs.registerLanguage('nestedtext', hljsGrammar);
  })();