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