1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function asciidoc(hljs) {
|
12 | const regex = hljs.regex;
|
13 | const HORIZONTAL_RULE = {
|
14 | begin: '^\'{3,}[ \\t]*$',
|
15 | relevance: 10
|
16 | };
|
17 | const ESCAPED_FORMATTING = [
|
18 |
|
19 | {
|
20 | begin: /\\[*_`]/
|
21 | },
|
22 |
|
23 |
|
24 |
|
25 | {
|
26 | begin: /\\\\\*{2}[^\n]*?\*{2}/
|
27 | },
|
28 | {
|
29 | begin: /\\\\_{2}[^\n]*_{2}/
|
30 | },
|
31 | {
|
32 | begin: /\\\\`{2}[^\n]*`{2}/
|
33 | },
|
34 |
|
35 |
|
36 | {
|
37 | begin: /[:;}][*_`](?![*_`])/
|
38 | }
|
39 | ];
|
40 | const STRONG = [
|
41 |
|
42 | {
|
43 | className: 'strong',
|
44 | begin: /\*{2}([^\n]+?)\*{2}/
|
45 | },
|
46 |
|
47 | {
|
48 | className: 'strong',
|
49 | begin: regex.concat(
|
50 | /\*\*/,
|
51 | /((\*(?!\*)|\\[^\n]|[^*\n\\])+\n)+/,
|
52 | /(\*(?!\*)|\\[^\n]|[^*\n\\])*/,
|
53 | /\*\*/
|
54 | ),
|
55 | relevance: 0
|
56 | },
|
57 |
|
58 | {
|
59 | className: 'strong',
|
60 |
|
61 | begin: /\B\*(\S|\S[^\n]*?\S)\*(?!\w)/
|
62 | },
|
63 |
|
64 | {
|
65 | className: 'strong',
|
66 |
|
67 | begin: /\*[^\s]([^\n]+\n)+([^\n]+)\*/
|
68 | }
|
69 | ];
|
70 | const EMPHASIS = [
|
71 |
|
72 | {
|
73 | className: 'emphasis',
|
74 | begin: /_{2}([^\n]+?)_{2}/
|
75 | },
|
76 |
|
77 | {
|
78 | className: 'emphasis',
|
79 | begin: regex.concat(
|
80 | /__/,
|
81 | /((_(?!_)|\\[^\n]|[^_\n\\])+\n)+/,
|
82 | /(_(?!_)|\\[^\n]|[^_\n\\])*/,
|
83 | /__/
|
84 | ),
|
85 | relevance: 0
|
86 | },
|
87 |
|
88 | {
|
89 | className: 'emphasis',
|
90 |
|
91 | begin: /\b_(\S|\S[^\n]*?\S)_(?!\w)/
|
92 | },
|
93 |
|
94 | {
|
95 | className: 'emphasis',
|
96 |
|
97 | begin: /_[^\s]([^\n]+\n)+([^\n]+)_/
|
98 | },
|
99 |
|
100 | {
|
101 | className: 'emphasis',
|
102 |
|
103 | begin: '\\B\'(?![\'\\s])',
|
104 | end: '(\\n{2}|\')',
|
105 |
|
106 | contains: [{
|
107 | begin: '\\\\\'\\w',
|
108 | relevance: 0
|
109 | }],
|
110 | relevance: 0
|
111 | }
|
112 | ];
|
113 | const ADMONITION = {
|
114 | className: 'symbol',
|
115 | begin: '^(NOTE|TIP|IMPORTANT|WARNING|CAUTION):\\s+',
|
116 | relevance: 10
|
117 | };
|
118 | const BULLET_LIST = {
|
119 | className: 'bullet',
|
120 | begin: '^(\\*+|-+|\\.+|[^\\n]+?::)\\s+'
|
121 | };
|
122 |
|
123 | return {
|
124 | name: 'AsciiDoc',
|
125 | aliases: ['adoc'],
|
126 | contains: [
|
127 |
|
128 | hljs.COMMENT(
|
129 | '^/{4,}\\n',
|
130 | '\\n/{4,}$',
|
131 |
|
132 |
|
133 |
|
134 | {
|
135 | relevance: 10
|
136 | }
|
137 | ),
|
138 |
|
139 | hljs.COMMENT(
|
140 | '^//',
|
141 | '$',
|
142 | {
|
143 | relevance: 0
|
144 | }
|
145 | ),
|
146 |
|
147 | {
|
148 | className: 'title',
|
149 | begin: '^\\.\\w.*$'
|
150 | },
|
151 |
|
152 | {
|
153 | begin: '^[=\\*]{4,}\\n',
|
154 | end: '\\n^[=\\*]{4,}$',
|
155 | relevance: 10
|
156 | },
|
157 |
|
158 | {
|
159 | className: 'section',
|
160 | relevance: 10,
|
161 | variants: [
|
162 | {
|
163 | begin: '^(={1,6})[ \t].+?([ \t]\\1)?$'
|
164 | },
|
165 | {
|
166 | begin: '^[^\\[\\]\\n]+?\\n[=\\-~\\^\\+]{2,}$'
|
167 | }
|
168 | ]
|
169 | },
|
170 |
|
171 | {
|
172 | className: 'meta',
|
173 | begin: '^:.+?:',
|
174 | end: '\\s',
|
175 | excludeEnd: true,
|
176 | relevance: 10
|
177 | },
|
178 |
|
179 | {
|
180 | className: 'meta',
|
181 | begin: '^\\[.+?\\]$',
|
182 | relevance: 0
|
183 | },
|
184 |
|
185 | {
|
186 | className: 'quote',
|
187 | begin: '^_{4,}\\n',
|
188 | end: '\\n_{4,}$',
|
189 | relevance: 10
|
190 | },
|
191 |
|
192 | {
|
193 | className: 'code',
|
194 | begin: '^[\\-\\.]{4,}\\n',
|
195 | end: '\\n[\\-\\.]{4,}$',
|
196 | relevance: 10
|
197 | },
|
198 |
|
199 | {
|
200 | begin: '^\\+{4,}\\n',
|
201 | end: '\\n\\+{4,}$',
|
202 | contains: [{
|
203 | begin: '<',
|
204 | end: '>',
|
205 | subLanguage: 'xml',
|
206 | relevance: 0
|
207 | }],
|
208 | relevance: 10
|
209 | },
|
210 |
|
211 | BULLET_LIST,
|
212 | ADMONITION,
|
213 | ...ESCAPED_FORMATTING,
|
214 | ...STRONG,
|
215 | ...EMPHASIS,
|
216 |
|
217 |
|
218 | {
|
219 | className: 'string',
|
220 | variants: [
|
221 | {
|
222 | begin: "``.+?''"
|
223 | },
|
224 | {
|
225 | begin: "`.+?'"
|
226 | }
|
227 | ]
|
228 | },
|
229 |
|
230 | {
|
231 | className: 'code',
|
232 | begin: /`{2}/,
|
233 | end: /(\n{2}|`{2})/
|
234 | },
|
235 |
|
236 | {
|
237 | className: 'code',
|
238 | begin: '(`.+?`|\\+.+?\\+)',
|
239 | relevance: 0
|
240 | },
|
241 |
|
242 | {
|
243 | className: 'code',
|
244 | begin: '^[ \\t]',
|
245 | end: '$',
|
246 | relevance: 0
|
247 | },
|
248 | HORIZONTAL_RULE,
|
249 |
|
250 | {
|
251 | begin: '(link:)?(http|https|ftp|file|irc|image:?):\\S+?\\[[^[]*?\\]',
|
252 | returnBegin: true,
|
253 | contains: [
|
254 | {
|
255 | begin: '(link|image:?):',
|
256 | relevance: 0
|
257 | },
|
258 | {
|
259 | className: 'link',
|
260 | begin: '\\w',
|
261 | end: '[^\\[]+',
|
262 | relevance: 0
|
263 | },
|
264 | {
|
265 | className: 'string',
|
266 | begin: '\\[',
|
267 | end: '\\]',
|
268 | excludeBegin: true,
|
269 | excludeEnd: true,
|
270 | relevance: 0
|
271 | }
|
272 | ],
|
273 | relevance: 10
|
274 | }
|
275 | ]
|
276 | };
|
277 | }
|
278 |
|
279 | export { asciidoc as default };
|