]> luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/asciidoc.js
Initial commit.
[flow-web.git] / static / highlight / es / languages / asciidoc.js
1 /*! `asciidoc` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar = (function () {
3 'use strict';
4
5 /*
6 Language: AsciiDoc
7 Requires: xml.js
8 Author: Dan Allen <dan.j.allen@gmail.com>
9 Website: http://asciidoc.org
10 Description: A semantic, text-based document format that can be exported to HTML, DocBook and other backends.
11 Category: markup
12 */
13
14 /** @type LanguageFn */
15 function asciidoc(hljs) {
16 const regex = hljs.regex;
17 const HORIZONTAL_RULE = {
18 begin: '^\'{3,}[ \\t]*$',
19 relevance: 10
20 };
21 const ESCAPED_FORMATTING = [
22 // escaped constrained formatting marks (i.e., \* \_ or \`)
23 { begin: /\\[*_`]/ },
24 // escaped unconstrained formatting marks (i.e., \\** \\__ or \\``)
25 // must ignore until the next formatting marks
26 // this rule might not be 100% compliant with Asciidoctor 2.0 but we are entering undefined behavior territory...
27 { begin: /\\\\\*{2}[^\n]*?\*{2}/ },
28 { begin: /\\\\_{2}[^\n]*_{2}/ },
29 { begin: /\\\\`{2}[^\n]*`{2}/ },
30 // guard: constrained formatting mark may not be preceded by ":", ";" or
31 // "}". match these so the constrained rule doesn't see them
32 { begin: /[:;}][*_`](?![*_`])/ }
33 ];
34 const STRONG = [
35 // inline unconstrained strong (single line)
36 {
37 className: 'strong',
38 begin: /\*{2}([^\n]+?)\*{2}/
39 },
40 // inline unconstrained strong (multi-line)
41 {
42 className: 'strong',
43 begin: regex.concat(
44 /\*\*/,
45 /((\*(?!\*)|\\[^\n]|[^*\n\\])+\n)+/,
46 /(\*(?!\*)|\\[^\n]|[^*\n\\])*/,
47 /\*\*/
48 ),
49 relevance: 0
50 },
51 // inline constrained strong (single line)
52 {
53 className: 'strong',
54 // must not precede or follow a word character
55 begin: /\B\*(\S|\S[^\n]*?\S)\*(?!\w)/
56 },
57 // inline constrained strong (multi-line)
58 {
59 className: 'strong',
60 // must not precede or follow a word character
61 begin: /\*[^\s]([^\n]+\n)+([^\n]+)\*/
62 }
63 ];
64 const EMPHASIS = [
65 // inline unconstrained emphasis (single line)
66 {
67 className: 'emphasis',
68 begin: /_{2}([^\n]+?)_{2}/
69 },
70 // inline unconstrained emphasis (multi-line)
71 {
72 className: 'emphasis',
73 begin: regex.concat(
74 /__/,
75 /((_(?!_)|\\[^\n]|[^_\n\\])+\n)+/,
76 /(_(?!_)|\\[^\n]|[^_\n\\])*/,
77 /__/
78 ),
79 relevance: 0
80 },
81 // inline constrained emphasis (single line)
82 {
83 className: 'emphasis',
84 // must not precede or follow a word character
85 begin: /\b_(\S|\S[^\n]*?\S)_(?!\w)/
86 },
87 // inline constrained emphasis (multi-line)
88 {
89 className: 'emphasis',
90 // must not precede or follow a word character
91 begin: /_[^\s]([^\n]+\n)+([^\n]+)_/
92 },
93 // inline constrained emphasis using single quote (legacy)
94 {
95 className: 'emphasis',
96 // must not follow a word character or be followed by a single quote or space
97 begin: '\\B\'(?![\'\\s])',
98 end: '(\\n{2}|\')',
99 // allow escaped single quote followed by word char
100 contains: [
101 {
102 begin: '\\\\\'\\w',
103 relevance: 0
104 }
105 ],
106 relevance: 0
107 }
108 ];
109 const ADMONITION = {
110 className: 'symbol',
111 begin: '^(NOTE|TIP|IMPORTANT|WARNING|CAUTION):\\s+',
112 relevance: 10
113 };
114 const BULLET_LIST = {
115 className: 'bullet',
116 begin: '^(\\*+|-+|\\.+|[^\\n]+?::)\\s+'
117 };
118
119 return {
120 name: 'AsciiDoc',
121 aliases: [ 'adoc' ],
122 contains: [
123 // block comment
124 hljs.COMMENT(
125 '^/{4,}\\n',
126 '\\n/{4,}$',
127 // can also be done as...
128 // '^/{4,}$',
129 // '^/{4,}$',
130 { relevance: 10 }
131 ),
132 // line comment
133 hljs.COMMENT(
134 '^//',
135 '$',
136 { relevance: 0 }
137 ),
138 // title
139 {
140 className: 'title',
141 begin: '^\\.\\w.*$'
142 },
143 // example, admonition & sidebar blocks
144 {
145 begin: '^[=\\*]{4,}\\n',
146 end: '\\n^[=\\*]{4,}$',
147 relevance: 10
148 },
149 // headings
150 {
151 className: 'section',
152 relevance: 10,
153 variants: [
154 { begin: '^(={1,6})[ \t].+?([ \t]\\1)?$' },
155 { begin: '^[^\\[\\]\\n]+?\\n[=\\-~\\^\\+]{2,}$' }
156 ]
157 },
158 // document attributes
159 {
160 className: 'meta',
161 begin: '^:.+?:',
162 end: '\\s',
163 excludeEnd: true,
164 relevance: 10
165 },
166 // block attributes
167 {
168 className: 'meta',
169 begin: '^\\[.+?\\]$',
170 relevance: 0
171 },
172 // quoteblocks
173 {
174 className: 'quote',
175 begin: '^_{4,}\\n',
176 end: '\\n_{4,}$',
177 relevance: 10
178 },
179 // listing and literal blocks
180 {
181 className: 'code',
182 begin: '^[\\-\\.]{4,}\\n',
183 end: '\\n[\\-\\.]{4,}$',
184 relevance: 10
185 },
186 // passthrough blocks
187 {
188 begin: '^\\+{4,}\\n',
189 end: '\\n\\+{4,}$',
190 contains: [
191 {
192 begin: '<',
193 end: '>',
194 subLanguage: 'xml',
195 relevance: 0
196 }
197 ],
198 relevance: 10
199 },
200
201 BULLET_LIST,
202 ADMONITION,
203 ...ESCAPED_FORMATTING,
204 ...STRONG,
205 ...EMPHASIS,
206
207 // inline smart quotes
208 {
209 className: 'string',
210 variants: [
211 { begin: "``.+?''" },
212 { begin: "`.+?'" }
213 ]
214 },
215 // inline unconstrained emphasis
216 {
217 className: 'code',
218 begin: /`{2}/,
219 end: /(\n{2}|`{2})/
220 },
221 // inline code snippets (TODO should get same treatment as strong and emphasis)
222 {
223 className: 'code',
224 begin: '(`.+?`|\\+.+?\\+)',
225 relevance: 0
226 },
227 // indented literal block
228 {
229 className: 'code',
230 begin: '^[ \\t]',
231 end: '$',
232 relevance: 0
233 },
234 HORIZONTAL_RULE,
235 // images and links
236 {
237 begin: '(link:)?(http|https|ftp|file|irc|image:?):\\S+?\\[[^[]*?\\]',
238 returnBegin: true,
239 contains: [
240 {
241 begin: '(link|image:?):',
242 relevance: 0
243 },
244 {
245 className: 'link',
246 begin: '\\w',
247 end: '[^\\[]+',
248 relevance: 0
249 },
250 {
251 className: 'string',
252 begin: '\\[',
253 end: '\\]',
254 excludeBegin: true,
255 excludeEnd: true,
256 relevance: 0
257 }
258 ],
259 relevance: 10
260 }
261 ]
262 };
263 }
264
265 return asciidoc;
266
267 })();
268 ;
269 export default hljsGrammar;