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