]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/yaml.js
1 /*! `yaml` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
8 Description: Yet Another Markdown Language
9 Author: Stefan Wienert <stwienert@gmail.com>
10 Contributors: Carl Baxter <carl@cbax.tech>
12 Website: https://yaml.org
13 Category: common, config
16 const LITERALS
= 'true false yes no null';
18 // YAML spec allows non-reserved URI characters in tags.
19 const URI_CHARACTERS
= '[\\w#;/?:@&=+$,.~*\'()[\\]]+';
21 // Define keys as starting with a word character
22 // ...containing word chars, spaces, colons, forward-slashes, hyphens and periods
23 // ...and ending with a colon followed immediately by a space, tab or newline.
24 // The YAML spec allows for much more than this, but this covers most use-cases.
28 // added brackets support and special char support
29 { begin: /[\w
*@][\w
*@ :()\./-]*:(?=[ \t]|$)/ },
30 { // double quoted keys - with brackets and special char support
31 begin: /"[\w*@][\w*@ :()\./-]*":(?=[ \t]|$)/ },
32 { // single quoted keys - with brackets and special char support
33 begin: /'[\w*@][\w*@ :()\./-]*':(?=[ \t]|$)/ },
37 const TEMPLATE_VARIABLES
= {
38 className: 'template-variable',
40 { // jinja templates Ansible
51 const SINGLE_QUOTE_STRING
= {
76 hljs
.BACKSLASH_ESCAPE
,
81 // Strings inside of value containers (objects) can't contain braces,
82 // brackets, or commas
83 const CONTAINER_STRING
= hljs
.inherit(STRING
, { variants: [
98 { begin: /[^\s,{}[\]]+/ }
101 const DATE_RE
= '[0-9]{4}(-[0-9][0-9]){0,2}';
102 const TIME_RE
= '([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?';
103 const FRACTION_RE
= '(\\.[0-9]*)?';
104 const ZONE_RE
= '([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?';
107 begin: '\\b' + DATE_RE
+ TIME_RE
+ FRACTION_RE
+ ZONE_RE
+ '\\b'
110 const VALUE_CONTAINER
= {
112 endsWithParent: true,
120 contains: [ VALUE_CONTAINER
],
127 contains: [ VALUE_CONTAINER
],
139 { // multi line string
140 // Blocks start with a | or > followed by a newline
142 // Indentation of subsequent lines must be the same to
143 // be considered part of the block
145 begin: '[\\|>]([1-9]?[+-])?[ ]*\\n( +)[^ ][^\\n]*\\n(\\2[^\\n]+\\n?)*'
157 begin: '!\\w+!' + URI_CHARACTERS
159 // https://yaml.org/spec/1.2/spec.html#id2784064
162 begin: '!<' + URI_CHARACTERS
+ ">"
166 begin: '!' + URI_CHARACTERS
170 begin: '!!' + URI_CHARACTERS
172 { // fragment id &ref
174 begin: '&' + hljs
.UNDERSCORE_IDENT_RE
+ '$'
176 { // fragment reference *ref
178 begin: '\\*' + hljs
.UNDERSCORE_IDENT_RE
+ '$'
182 // TODO: remove |$ hack when we have proper look-ahead support
186 hljs
.HASH_COMMENT_MODE
,
188 beginKeywords: LITERALS
,
189 keywords: { literal: LITERALS
}
192 // numbers are any valid C-style number that
193 // sit isolated from other words
196 begin: hljs
.C_NUMBER_RE
+ '\\b',
205 const VALUE_MODES
= [ ...MODES
];
207 VALUE_MODES
.push(CONTAINER_STRING
);
208 VALUE_CONTAINER
.contains
= VALUE_MODES
;
212 case_insensitive: true,
222 hljs
.registerLanguage('yaml', hljsGrammar
);