1 | (function (Prism) {
|
2 |
|
3 |
|
4 |
|
5 | var anchorOrAlias = /[*&][^\s[\]{},]+/;
|
6 |
|
7 | var tag = /!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/;
|
8 |
|
9 | var properties = '(?:' + tag.source + '(?:[ \t]+' + anchorOrAlias.source + ')?|'
|
10 | + anchorOrAlias.source + '(?:[ \t]+' + tag.source + ')?)';
|
11 |
|
12 |
|
13 |
|
14 | var plainKey = /(?:[^\s\x00-\x08\x0e-\x1f!"#%&'*,\-:>?@[\]`{|}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]|[?:-]<PLAIN>)(?:[ \t]*(?:(?![#:])<PLAIN>|:<PLAIN>))*/.source
|
15 | .replace(/<PLAIN>/g, function () { return /[^\s\x00-\x08\x0e-\x1f,[\]{}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]/.source; });
|
16 | var string = /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/.source;
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function createValuePattern(value, flags) {
|
25 | flags = (flags || '').replace(/m/g, '') + 'm';
|
26 | var pattern = /([:\-,[{]\s*(?:\s<<prop>>[ \t]+)?)(?:<<value>>)(?=[ \t]*(?:$|,|\]|\}|(?:[\r\n]\s*)?#))/.source
|
27 | .replace(/<<prop>>/g, function () { return properties; }).replace(/<<value>>/g, function () { return value; });
|
28 | return RegExp(pattern, flags);
|
29 | }
|
30 |
|
31 | Prism.languages.yaml = {
|
32 | 'scalar': {
|
33 | pattern: RegExp(/([\-:]\s*(?:\s<<prop>>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\S[^\r\n]*(?:\2[^\r\n]+)*)/.source
|
34 | .replace(/<<prop>>/g, function () { return properties; })),
|
35 | lookbehind: true,
|
36 | alias: 'string'
|
37 | },
|
38 | 'comment': /#.*/,
|
39 | 'key': {
|
40 | pattern: RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<<prop>>[ \t]+)?)<<key>>(?=\s*:\s)/.source
|
41 | .replace(/<<prop>>/g, function () { return properties; })
|
42 | .replace(/<<key>>/g, function () { return '(?:' + plainKey + '|' + string + ')'; })),
|
43 | lookbehind: true,
|
44 | greedy: true,
|
45 | alias: 'atrule'
|
46 | },
|
47 | 'directive': {
|
48 | pattern: /(^[ \t]*)%.+/m,
|
49 | lookbehind: true,
|
50 | alias: 'important'
|
51 | },
|
52 | 'datetime': {
|
53 | pattern: createValuePattern(/\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?(?:[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?))?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?/.source),
|
54 | lookbehind: true,
|
55 | alias: 'number'
|
56 | },
|
57 | 'boolean': {
|
58 | pattern: createValuePattern(/true|false/.source, 'i'),
|
59 | lookbehind: true,
|
60 | alias: 'important'
|
61 | },
|
62 | 'null': {
|
63 | pattern: createValuePattern(/null|~/.source, 'i'),
|
64 | lookbehind: true,
|
65 | alias: 'important'
|
66 | },
|
67 | 'string': {
|
68 | pattern: createValuePattern(string),
|
69 | lookbehind: true,
|
70 | greedy: true
|
71 | },
|
72 | 'number': {
|
73 | pattern: createValuePattern(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source, 'i'),
|
74 | lookbehind: true
|
75 | },
|
76 | 'tag': tag,
|
77 | 'important': anchorOrAlias,
|
78 | 'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
|
79 | };
|
80 |
|
81 | Prism.languages.yml = Prism.languages.yaml;
|
82 |
|
83 | }(Prism));
|