source: node_modules/refractor/lang/yaml.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 3.9 KB
Line 
1'use strict'
2
3module.exports = yaml
4yaml.displayName = 'yaml'
5yaml.aliases = ['yml']
6function yaml(Prism) {
7 ;(function (Prism) {
8 // https://yaml.org/spec/1.2/spec.html#c-ns-anchor-property
9 // https://yaml.org/spec/1.2/spec.html#c-ns-alias-node
10 var anchorOrAlias = /[*&][^\s[\]{},]+/ // https://yaml.org/spec/1.2/spec.html#c-ns-tag-property
11 var tag =
12 /!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/ // https://yaml.org/spec/1.2/spec.html#c-ns-properties(n,c)
13 var properties =
14 '(?:' +
15 tag.source +
16 '(?:[ \t]+' +
17 anchorOrAlias.source +
18 ')?|' +
19 anchorOrAlias.source +
20 '(?:[ \t]+' +
21 tag.source +
22 ')?)' // https://yaml.org/spec/1.2/spec.html#ns-plain(n,c)
23 // This is a simplified version that doesn't support "#" and multiline keys
24 // All these long scarry character classes are simplified versions of YAML's characters
25 var plainKey =
26 /(?:[^\s\x00-\x08\x0e-\x1f!"#%&'*,\-:>?@[\]`{|}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]|[?:-]<PLAIN>)(?:[ \t]*(?:(?![#:])<PLAIN>|:<PLAIN>))*/.source.replace(
27 /<PLAIN>/g,
28 function () {
29 return /[^\s\x00-\x08\x0e-\x1f,[\]{}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]/
30 .source
31 }
32 )
33 var string = /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/.source
34 /**
35 *
36 * @param {string} value
37 * @param {string} [flags]
38 * @returns {RegExp}
39 */
40 function createValuePattern(value, flags) {
41 flags = (flags || '').replace(/m/g, '') + 'm' // add m flag
42 var pattern =
43 /([:\-,[{]\s*(?:\s<<prop>>[ \t]+)?)(?:<<value>>)(?=[ \t]*(?:$|,|\]|\}|(?:[\r\n]\s*)?#))/.source
44 .replace(/<<prop>>/g, function () {
45 return properties
46 })
47 .replace(/<<value>>/g, function () {
48 return value
49 })
50 return RegExp(pattern, flags)
51 }
52 Prism.languages.yaml = {
53 scalar: {
54 pattern: RegExp(
55 /([\-:]\s*(?:\s<<prop>>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\S[^\r\n]*(?:\2[^\r\n]+)*)/.source.replace(
56 /<<prop>>/g,
57 function () {
58 return properties
59 }
60 )
61 ),
62 lookbehind: true,
63 alias: 'string'
64 },
65 comment: /#.*/,
66 key: {
67 pattern: RegExp(
68 /((?:^|[:\-,[{\r\n?])[ \t]*(?:<<prop>>[ \t]+)?)<<key>>(?=\s*:\s)/.source
69 .replace(/<<prop>>/g, function () {
70 return properties
71 })
72 .replace(/<<key>>/g, function () {
73 return '(?:' + plainKey + '|' + string + ')'
74 })
75 ),
76 lookbehind: true,
77 greedy: true,
78 alias: 'atrule'
79 },
80 directive: {
81 pattern: /(^[ \t]*)%.+/m,
82 lookbehind: true,
83 alias: 'important'
84 },
85 datetime: {
86 pattern: createValuePattern(
87 /\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*)?)?/
88 .source
89 ),
90 lookbehind: true,
91 alias: 'number'
92 },
93 boolean: {
94 pattern: createValuePattern(/false|true/.source, 'i'),
95 lookbehind: true,
96 alias: 'important'
97 },
98 null: {
99 pattern: createValuePattern(/null|~/.source, 'i'),
100 lookbehind: true,
101 alias: 'important'
102 },
103 string: {
104 pattern: createValuePattern(string),
105 lookbehind: true,
106 greedy: true
107 },
108 number: {
109 pattern: createValuePattern(
110 /[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/
111 .source,
112 'i'
113 ),
114 lookbehind: true
115 },
116 tag: tag,
117 important: anchorOrAlias,
118 punctuation: /---|[:[\]{}\-,|>?]|\.\.\./
119 }
120 Prism.languages.yml = Prism.languages.yaml
121 })(Prism)
122}
Note: See TracBrowser for help on using the repository browser.