]> luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/yaml.js
Initial commit.
[flow-web.git] / static / highlight / es / languages / yaml.js
1 /*! `yaml` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar = (function () {
3 'use strict';
4
5 /*
6 Language: YAML
7 Description: Yet Another Markdown Language
8 Author: Stefan Wienert <stwienert@gmail.com>
9 Contributors: Carl Baxter <carl@cbax.tech>
10 Requires: ruby.js
11 Website: https://yaml.org
12 Category: common, config
13 */
14 function yaml(hljs) {
15 const LITERALS = 'true false yes no null';
16
17 // YAML spec allows non-reserved URI characters in tags.
18 const URI_CHARACTERS = '[\\w#;/?:@&=+$,.~*\'()[\\]]+';
19
20 // Define keys as starting with a word character
21 // ...containing word chars, spaces, colons, forward-slashes, hyphens and periods
22 // ...and ending with a colon followed immediately by a space, tab or newline.
23 // The YAML spec allows for much more than this, but this covers most use-cases.
24 const KEY = {
25 className: 'attr',
26 variants: [
27 // added brackets support and special char support
28 { begin: /[\w*@][\w*@ :()\./-]*:(?=[ \t]|$)/ },
29 { // double quoted keys - with brackets and special char support
30 begin: /"[\w*@][\w*@ :()\./-]*":(?=[ \t]|$)/ },
31 { // single quoted keys - with brackets and special char support
32 begin: /'[\w*@][\w*@ :()\./-]*':(?=[ \t]|$)/ },
33 ]
34 };
35
36 const TEMPLATE_VARIABLES = {
37 className: 'template-variable',
38 variants: [
39 { // jinja templates Ansible
40 begin: /\{\{/,
41 end: /\}\}/
42 },
43 { // Ruby i18n
44 begin: /%\{/,
45 end: /\}/
46 }
47 ]
48 };
49
50 const SINGLE_QUOTE_STRING = {
51 className: 'string',
52 relevance: 0,
53 begin: /'/,
54 end: /'/,
55 contains: [
56 {
57 match: /''/,
58 scope: 'char.escape',
59 relevance: 0
60 }
61 ]
62 };
63
64 const STRING = {
65 className: 'string',
66 relevance: 0,
67 variants: [
68 {
69 begin: /"/,
70 end: /"/
71 },
72 { begin: /\S+/ }
73 ],
74 contains: [
75 hljs.BACKSLASH_ESCAPE,
76 TEMPLATE_VARIABLES
77 ]
78 };
79
80 // Strings inside of value containers (objects) can't contain braces,
81 // brackets, or commas
82 const CONTAINER_STRING = hljs.inherit(STRING, { variants: [
83 {
84 begin: /'/,
85 end: /'/,
86 contains: [
87 {
88 begin: /''/,
89 relevance: 0
90 }
91 ]
92 },
93 {
94 begin: /"/,
95 end: /"/
96 },
97 { begin: /[^\s,{}[\]]+/ }
98 ] });
99
100 const DATE_RE = '[0-9]{4}(-[0-9][0-9]){0,2}';
101 const TIME_RE = '([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?';
102 const FRACTION_RE = '(\\.[0-9]*)?';
103 const ZONE_RE = '([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?';
104 const TIMESTAMP = {
105 className: 'number',
106 begin: '\\b' + DATE_RE + TIME_RE + FRACTION_RE + ZONE_RE + '\\b'
107 };
108
109 const VALUE_CONTAINER = {
110 end: ',',
111 endsWithParent: true,
112 excludeEnd: true,
113 keywords: LITERALS,
114 relevance: 0
115 };
116 const OBJECT = {
117 begin: /\{/,
118 end: /\}/,
119 contains: [ VALUE_CONTAINER ],
120 illegal: '\\n',
121 relevance: 0
122 };
123 const ARRAY = {
124 begin: '\\[',
125 end: '\\]',
126 contains: [ VALUE_CONTAINER ],
127 illegal: '\\n',
128 relevance: 0
129 };
130
131 const MODES = [
132 KEY,
133 {
134 className: 'meta',
135 begin: '^---\\s*$',
136 relevance: 10
137 },
138 { // multi line string
139 // Blocks start with a | or > followed by a newline
140 //
141 // Indentation of subsequent lines must be the same to
142 // be considered part of the block
143 className: 'string',
144 begin: '[\\|>]([1-9]?[+-])?[ ]*\\n( +)[^ ][^\\n]*\\n(\\2[^\\n]+\\n?)*'
145 },
146 { // Ruby/Rails erb
147 begin: '<%[%=-]?',
148 end: '[%-]?%>',
149 subLanguage: 'ruby',
150 excludeBegin: true,
151 excludeEnd: true,
152 relevance: 0
153 },
154 { // named tags
155 className: 'type',
156 begin: '!\\w+!' + URI_CHARACTERS
157 },
158 // https://yaml.org/spec/1.2/spec.html#id2784064
159 { // verbatim tags
160 className: 'type',
161 begin: '!<' + URI_CHARACTERS + ">"
162 },
163 { // primary tags
164 className: 'type',
165 begin: '!' + URI_CHARACTERS
166 },
167 { // secondary tags
168 className: 'type',
169 begin: '!!' + URI_CHARACTERS
170 },
171 { // fragment id &ref
172 className: 'meta',
173 begin: '&' + hljs.UNDERSCORE_IDENT_RE + '$'
174 },
175 { // fragment reference *ref
176 className: 'meta',
177 begin: '\\*' + hljs.UNDERSCORE_IDENT_RE + '$'
178 },
179 { // array listing
180 className: 'bullet',
181 // TODO: remove |$ hack when we have proper look-ahead support
182 begin: '-(?=[ ]|$)',
183 relevance: 0
184 },
185 hljs.HASH_COMMENT_MODE,
186 {
187 beginKeywords: LITERALS,
188 keywords: { literal: LITERALS }
189 },
190 TIMESTAMP,
191 // numbers are any valid C-style number that
192 // sit isolated from other words
193 {
194 className: 'number',
195 begin: hljs.C_NUMBER_RE + '\\b',
196 relevance: 0
197 },
198 OBJECT,
199 ARRAY,
200 SINGLE_QUOTE_STRING,
201 STRING
202 ];
203
204 const VALUE_MODES = [ ...MODES ];
205 VALUE_MODES.pop();
206 VALUE_MODES.push(CONTAINER_STRING);
207 VALUE_CONTAINER.contains = VALUE_MODES;
208
209 return {
210 name: 'YAML',
211 case_insensitive: true,
212 aliases: [ 'yml' ],
213 contains: MODES
214 };
215 }
216
217 return yaml;
218
219 })();
220 ;
221 export default hljsGrammar;