]> luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/xml.js
Initial commit.
[flow-web.git] / static / highlight / es / languages / xml.js
1 /*! `xml` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar = (function () {
3 'use strict';
4
5 /*
6 Language: HTML, XML
7 Website: https://www.w3.org/XML/
8 Category: common, web
9 Audit: 2020
10 */
11
12 /** @type LanguageFn */
13 function xml(hljs) {
14 const regex = hljs.regex;
15 // XML names can have the following additional letters: https://www.w3.org/TR/xml/#NT-NameChar
16 // OTHER_NAME_CHARS = /[:\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]/;
17 // Element names start with NAME_START_CHAR followed by optional other Unicode letters, ASCII digits, hyphens, underscores, and periods
18 // const TAG_NAME_RE = regex.concat(/[A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/, regex.optional(/[A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*:/), /[A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*/);;
19 // const XML_IDENT_RE = /[A-Z_a-z:\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]+/;
20 // const TAG_NAME_RE = regex.concat(/[A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/, regex.optional(/[A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*:/), /[A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*/);
21 // however, to cater for performance and more Unicode support rely simply on the Unicode letter class
22 const TAG_NAME_RE = regex.concat(/[\p{L}_]/u, regex.optional(/[\p{L}0-9_.-]*:/u), /[\p{L}0-9_.-]*/u);
23 const XML_IDENT_RE = /[\p{L}0-9._:-]+/u;
24 const XML_ENTITIES = {
25 className: 'symbol',
26 begin: /&[a-z]+;|&#[0-9]+;|&#x[a-f0-9]+;/
27 };
28 const XML_META_KEYWORDS = {
29 begin: /\s/,
30 contains: [
31 {
32 className: 'keyword',
33 begin: /#?[a-z_][a-z1-9_-]+/,
34 illegal: /\n/
35 }
36 ]
37 };
38 const XML_META_PAR_KEYWORDS = hljs.inherit(XML_META_KEYWORDS, {
39 begin: /\(/,
40 end: /\)/
41 });
42 const APOS_META_STRING_MODE = hljs.inherit(hljs.APOS_STRING_MODE, { className: 'string' });
43 const QUOTE_META_STRING_MODE = hljs.inherit(hljs.QUOTE_STRING_MODE, { className: 'string' });
44 const TAG_INTERNALS = {
45 endsWithParent: true,
46 illegal: /</,
47 relevance: 0,
48 contains: [
49 {
50 className: 'attr',
51 begin: XML_IDENT_RE,
52 relevance: 0
53 },
54 {
55 begin: /=\s*/,
56 relevance: 0,
57 contains: [
58 {
59 className: 'string',
60 endsParent: true,
61 variants: [
62 {
63 begin: /"/,
64 end: /"/,
65 contains: [ XML_ENTITIES ]
66 },
67 {
68 begin: /'/,
69 end: /'/,
70 contains: [ XML_ENTITIES ]
71 },
72 { begin: /[^\s"'=<>`]+/ }
73 ]
74 }
75 ]
76 }
77 ]
78 };
79 return {
80 name: 'HTML, XML',
81 aliases: [
82 'html',
83 'xhtml',
84 'rss',
85 'atom',
86 'xjb',
87 'xsd',
88 'xsl',
89 'plist',
90 'wsf',
91 'svg'
92 ],
93 case_insensitive: true,
94 unicodeRegex: true,
95 contains: [
96 {
97 className: 'meta',
98 begin: /<![a-z]/,
99 end: />/,
100 relevance: 10,
101 contains: [
102 XML_META_KEYWORDS,
103 QUOTE_META_STRING_MODE,
104 APOS_META_STRING_MODE,
105 XML_META_PAR_KEYWORDS,
106 {
107 begin: /\[/,
108 end: /\]/,
109 contains: [
110 {
111 className: 'meta',
112 begin: /<![a-z]/,
113 end: />/,
114 contains: [
115 XML_META_KEYWORDS,
116 XML_META_PAR_KEYWORDS,
117 QUOTE_META_STRING_MODE,
118 APOS_META_STRING_MODE
119 ]
120 }
121 ]
122 }
123 ]
124 },
125 hljs.COMMENT(
126 /<!--/,
127 /-->/,
128 { relevance: 10 }
129 ),
130 {
131 begin: /<!\[CDATA\[/,
132 end: /\]\]>/,
133 relevance: 10
134 },
135 XML_ENTITIES,
136 // xml processing instructions
137 {
138 className: 'meta',
139 end: /\?>/,
140 variants: [
141 {
142 begin: /<\?xml/,
143 relevance: 10,
144 contains: [
145 QUOTE_META_STRING_MODE
146 ]
147 },
148 {
149 begin: /<\?[a-z][a-z0-9]+/,
150 }
151 ]
152
153 },
154 {
155 className: 'tag',
156 /*
157 The lookahead pattern (?=...) ensures that 'begin' only matches
158 '<style' as a single word, followed by a whitespace or an
159 ending bracket.
160 */
161 begin: /<style(?=\s|>)/,
162 end: />/,
163 keywords: { name: 'style' },
164 contains: [ TAG_INTERNALS ],
165 starts: {
166 end: /<\/style>/,
167 returnEnd: true,
168 subLanguage: [
169 'css',
170 'xml'
171 ]
172 }
173 },
174 {
175 className: 'tag',
176 // See the comment in the <style tag about the lookahead pattern
177 begin: /<script(?=\s|>)/,
178 end: />/,
179 keywords: { name: 'script' },
180 contains: [ TAG_INTERNALS ],
181 starts: {
182 end: /<\/script>/,
183 returnEnd: true,
184 subLanguage: [
185 'javascript',
186 'handlebars',
187 'xml'
188 ]
189 }
190 },
191 // we need this for now for jSX
192 {
193 className: 'tag',
194 begin: /<>|<\/>/
195 },
196 // open tag
197 {
198 className: 'tag',
199 begin: regex.concat(
200 /</,
201 regex.lookahead(regex.concat(
202 TAG_NAME_RE,
203 // <tag/>
204 // <tag>
205 // <tag ...
206 regex.either(/\/>/, />/, /\s/)
207 ))
208 ),
209 end: /\/?>/,
210 contains: [
211 {
212 className: 'name',
213 begin: TAG_NAME_RE,
214 relevance: 0,
215 starts: TAG_INTERNALS
216 }
217 ]
218 },
219 // close tag
220 {
221 className: 'tag',
222 begin: regex.concat(
223 /<\//,
224 regex.lookahead(regex.concat(
225 TAG_NAME_RE, />/
226 ))
227 ),
228 contains: [
229 {
230 className: 'name',
231 begin: TAG_NAME_RE,
232 relevance: 0
233 },
234 {
235 begin: />/,
236 relevance: 0,
237 endsParent: true
238 }
239 ]
240 }
241 ]
242 };
243 }
244
245 return xml;
246
247 })();
248 ;
249 export default hljsGrammar;