UNPKG

1.51 kBJavaScriptView Raw
1/*
2Language: NestedText
3Description: NestedText is a file format for holding data that is to be entered, edited, or viewed by people.
4Website: https://nestedtext.org/
5Category: config
6*/
7
8/** @type LanguageFn */
9function nestedtext(hljs) {
10 const NESTED = {
11 match: [
12 /^\s*(?=\S)/, // have to look forward here to avoid polynomial backtracking
13 /[^:]+/,
14 /:\s*/,
15 /$/
16 ],
17 className: {
18 2: "attribute",
19 3: "punctuation"
20 }
21 };
22 const DICTIONARY_ITEM = {
23 match: [
24 /^\s*(?=\S)/, // have to look forward here to avoid polynomial backtracking
25 /[^:]*[^: ]/,
26 /[ ]*:/,
27 /[ ]/,
28 /.*$/
29 ],
30 className: {
31 2: "attribute",
32 3: "punctuation",
33 5: "string"
34 }
35 };
36 const STRING = {
37 match: [
38 /^\s*/,
39 />/,
40 /[ ]/,
41 /.*$/
42 ],
43 className: {
44 2: "punctuation",
45 4: "string"
46 }
47 };
48 const LIST_ITEM = {
49 variants: [
50 {
51 match: [
52 /^\s*/,
53 /-/,
54 /[ ]/,
55 /.*$/
56 ]
57 },
58 {
59 match: [
60 /^\s*/,
61 /-$/
62 ]
63 }
64 ],
65 className: {
66 2: "bullet",
67 4: "string"
68 }
69 };
70
71 return {
72 name: 'Nested Text',
73 aliases: [ 'nt' ],
74 contains: [
75 hljs.inherit(hljs.HASH_COMMENT_MODE, {
76 begin: /^\s*(?=#)/,
77 excludeBegin: true
78 }),
79 LIST_ITEM,
80 STRING,
81 NESTED,
82 DICTIONARY_ITEM
83 ]
84 };
85}
86
87export { nestedtext as default };