1 | (function (Prism) {
|
2 |
|
3 | var attributes = {
|
4 | pattern: /(^[ \t]*)\[(?!\[)(?:(["'$`])(?:(?!\2)[^\\]|\\.)*\2|\[(?:[^\[\]\\]|\\.)*\]|[^\[\]\\"'$`]|\\.)*\]/m,
|
5 | lookbehind: true,
|
6 | inside: {
|
7 | 'quoted': {
|
8 | pattern: /([$`])(?:(?!\1)[^\\]|\\.)*\1/,
|
9 | inside: {
|
10 | 'punctuation': /^[$`]|[$`]$/
|
11 | }
|
12 | },
|
13 | 'interpreted': {
|
14 | pattern: /'(?:[^'\\]|\\.)*'/,
|
15 | inside: {
|
16 | 'punctuation': /^'|'$/
|
17 |
|
18 | }
|
19 | },
|
20 | 'string': /"(?:[^"\\]|\\.)*"/,
|
21 | 'variable': /\w+(?==)/,
|
22 | 'punctuation': /^\[|\]$|,/,
|
23 | 'operator': /=/,
|
24 |
|
25 | 'attr-value': /(?!^\s+$).+/
|
26 | }
|
27 | };
|
28 |
|
29 | var asciidoc = Prism.languages.asciidoc = {
|
30 | 'comment-block': {
|
31 | pattern: /^(\/{4,})(?:\r?\n|\r)(?:[\s\S]*(?:\r?\n|\r))??\1/m,
|
32 | alias: 'comment'
|
33 | },
|
34 | 'table': {
|
35 | pattern: /^\|={3,}(?:(?:\r?\n|\r(?!\n)).*)*?(?:\r?\n|\r)\|={3,}$/m,
|
36 | inside: {
|
37 | 'specifiers': {
|
38 | pattern: /(?:(?:(?:\d+(?:\.\d+)?|\.\d+)[+*](?:[<^>](?:\.[<^>])?|\.[<^>])?|[<^>](?:\.[<^>])?|\.[<^>])[a-z]*|[a-z]+)(?=\|)/,
|
39 | alias: 'attr-value'
|
40 | },
|
41 | 'punctuation': {
|
42 | pattern: /(^|[^\\])[|!]=*/,
|
43 | lookbehind: true
|
44 | }
|
45 |
|
46 | }
|
47 | },
|
48 |
|
49 | 'passthrough-block': {
|
50 | pattern: /^(\+{4,})(?:\r?\n|\r)(?:[\s\S]*(?:\r?\n|\r))??\1$/m,
|
51 | inside: {
|
52 | 'punctuation': /^\++|\++$/
|
53 |
|
54 | }
|
55 | },
|
56 |
|
57 | 'literal-block': {
|
58 | pattern: /^(-{4,}|\.{4,})(?:\r?\n|\r)(?:[\s\S]*(?:\r?\n|\r))??\1$/m,
|
59 | inside: {
|
60 | 'punctuation': /^(?:-+|\.+)|(?:-+|\.+)$/
|
61 |
|
62 | }
|
63 | },
|
64 |
|
65 | 'other-block': {
|
66 | pattern: /^(--|\*{4,}|_{4,}|={4,})(?:\r?\n|\r)(?:[\s\S]*(?:\r?\n|\r))??\1$/m,
|
67 | inside: {
|
68 | 'punctuation': /^(?:-+|\*+|_+|=+)|(?:-+|\*+|_+|=+)$/
|
69 |
|
70 | }
|
71 | },
|
72 |
|
73 |
|
74 | 'list-punctuation': {
|
75 | pattern: /(^[ \t]*)(?:-|\*{1,5}|\.{1,5}|(?:[a-z]|\d+)\.|[xvi]+\))(?= )/im,
|
76 | lookbehind: true,
|
77 | alias: 'punctuation'
|
78 | },
|
79 | 'list-label': {
|
80 | pattern: /(^[ \t]*)[a-z\d].+(?::{2,4}|;;)(?=\s)/im,
|
81 | lookbehind: true,
|
82 | alias: 'symbol'
|
83 | },
|
84 | 'indented-block': {
|
85 | pattern: /((\r?\n|\r)\2)([ \t]+)\S.*(?:(?:\r?\n|\r)\3.+)*(?=\2{2}|$)/,
|
86 | lookbehind: true
|
87 | },
|
88 |
|
89 | 'comment': /^\/\/.*/m,
|
90 | 'title': {
|
91 | pattern: /^.+(?:\r?\n|\r)(?:={3,}|-{3,}|~{3,}|\^{3,}|\+{3,})$|^={1,5} .+|^\.(?![\s.]).*/m,
|
92 | alias: 'important',
|
93 | inside: {
|
94 | 'punctuation': /^(?:\.|=+)|(?:=+|-+|~+|\^+|\++)$/
|
95 |
|
96 | }
|
97 | },
|
98 | 'attribute-entry': {
|
99 | pattern: /^:[^:\r\n]+:(?: .*?(?: \+(?:\r?\n|\r).*?)*)?$/m,
|
100 | alias: 'tag'
|
101 | },
|
102 | 'attributes': attributes,
|
103 | 'hr': {
|
104 | pattern: /^'{3,}$/m,
|
105 | alias: 'punctuation'
|
106 | },
|
107 | 'page-break': {
|
108 | pattern: /^<{3,}$/m,
|
109 | alias: 'punctuation'
|
110 | },
|
111 | 'admonition': {
|
112 | pattern: /^(?:TIP|NOTE|IMPORTANT|WARNING|CAUTION):/m,
|
113 | alias: 'keyword'
|
114 | },
|
115 | 'callout': [
|
116 | {
|
117 | pattern: /(^[ \t]*)<?\d*>/m,
|
118 | lookbehind: true,
|
119 | alias: 'symbol'
|
120 | },
|
121 | {
|
122 | pattern: /<\d+>/,
|
123 | alias: 'symbol'
|
124 | }
|
125 | ],
|
126 | 'macro': {
|
127 | pattern: /\b[a-z\d][a-z\d-]*::?(?:[^\s\[\]]*\[(?:[^\]\\"']|(["'])(?:(?!\1)[^\\]|\\.)*\1|\\.)*\])/,
|
128 | inside: {
|
129 | 'function': /^[a-z\d-]+(?=:)/,
|
130 | 'punctuation': /^::?/,
|
131 | 'attributes': {
|
132 | pattern: /(?:\[(?:[^\]\\"']|(["'])(?:(?!\1)[^\\]|\\.)*\1|\\.)*\])/,
|
133 | inside: attributes.inside
|
134 | }
|
135 | }
|
136 | },
|
137 | 'inline': {
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | pattern: /(^|[^\\])(?:(?:\B\[(?:[^\]\\"']|(["'])(?:(?!\2)[^\\]|\\.)*\2|\\.)*\])?(?:\b_(?!\s)(?: _|[^_\\\r\n]|\\.)+(?:(?:\r?\n|\r)(?: _|[^_\\\r\n]|\\.)+)*_\b|\B``(?!\s).+?(?:(?:\r?\n|\r).+?)*''\B|\B`(?!\s)(?:[^`'\s]|\s+\S)+['`]\B|\B(['*+#])(?!\s)(?: \3|(?!\3)[^\\\r\n]|\\.)+(?:(?:\r?\n|\r)(?: \3|(?!\3)[^\\\r\n]|\\.)+)*\3\B)|(?:\[(?:[^\]\\"']|(["'])(?:(?!\4)[^\\]|\\.)*\4|\\.)*\])?(?:(__|\*\*|\+\+\+?|##|\$\$|[~^]).+?(?:(?:\r?\n|\r).+?)*\5|\{[^}\r\n]+\}|\[\[\[?.+?(?:(?:\r?\n|\r).+?)*\]?\]\]|<<.+?(?:(?:\r?\n|\r).+?)*>>|\(\(\(?.+?(?:(?:\r?\n|\r).+?)*\)?\)\)))/m,
|
153 | lookbehind: true,
|
154 | inside: {
|
155 | 'attributes': attributes,
|
156 | 'url': {
|
157 | pattern: /^(?:\[\[\[?.+?\]?\]\]|<<.+?>>)$/,
|
158 | inside: {
|
159 | 'punctuation': /^(?:\[\[\[?|<<)|(?:\]\]\]?|>>)$/
|
160 | }
|
161 | },
|
162 | 'attribute-ref': {
|
163 | pattern: /^\{.+\}$/,
|
164 | inside: {
|
165 | 'variable': {
|
166 | pattern: /(^\{)[a-z\d,+_-]+/,
|
167 | lookbehind: true
|
168 | },
|
169 | 'operator': /^[=?!#%@$]|!(?=[:}])/,
|
170 | 'punctuation': /^\{|\}$|::?/
|
171 | }
|
172 | },
|
173 | 'italic': {
|
174 | pattern: /^(['_])[\s\S]+\1$/,
|
175 | inside: {
|
176 | 'punctuation': /^(?:''?|__?)|(?:''?|__?)$/
|
177 | }
|
178 | },
|
179 | 'bold': {
|
180 | pattern: /^\*[\s\S]+\*$/,
|
181 | inside: {
|
182 | punctuation: /^\*\*?|\*\*?$/
|
183 | }
|
184 | },
|
185 | 'punctuation': /^(?:``?|\+{1,3}|##?|\$\$|[~^]|\(\(\(?)|(?:''?|\+{1,3}|##?|\$\$|[~^`]|\)?\)\))$/
|
186 | }
|
187 | },
|
188 | 'replacement': {
|
189 | pattern: /\((?:C|TM|R)\)/,
|
190 | alias: 'builtin'
|
191 | },
|
192 | 'entity': /&#?[\da-z]{1,8};/i,
|
193 | 'line-continuation': {
|
194 | pattern: /(^| )\+$/m,
|
195 | lookbehind: true,
|
196 | alias: 'punctuation'
|
197 | }
|
198 | };
|
199 |
|
200 |
|
201 |
|
202 |
|
203 | function copyFromAsciiDoc(keys) {
|
204 | keys = keys.split(' ');
|
205 |
|
206 | var o = {};
|
207 | for (var i = 0, l = keys.length; i < l; i++) {
|
208 | o[keys[i]] = asciidoc[keys[i]];
|
209 | }
|
210 | return o;
|
211 | }
|
212 |
|
213 | attributes.inside['interpreted'].inside.rest = copyFromAsciiDoc('macro inline replacement entity');
|
214 |
|
215 | asciidoc['passthrough-block'].inside.rest = copyFromAsciiDoc('macro');
|
216 |
|
217 | asciidoc['literal-block'].inside.rest = copyFromAsciiDoc('callout');
|
218 |
|
219 | asciidoc['table'].inside.rest = copyFromAsciiDoc('comment-block passthrough-block literal-block other-block list-punctuation indented-block comment title attribute-entry attributes hr page-break admonition list-label callout macro inline replacement entity line-continuation');
|
220 |
|
221 | asciidoc['other-block'].inside.rest = copyFromAsciiDoc('table list-punctuation indented-block comment attribute-entry attributes hr page-break admonition list-label macro inline replacement entity line-continuation');
|
222 |
|
223 | asciidoc['title'].inside.rest = copyFromAsciiDoc('macro inline replacement entity');
|
224 |
|
225 |
|
226 |
|
227 | Prism.hooks.add('wrap', function (env) {
|
228 | if (env.type === 'entity') {
|
229 | env.attributes['title'] = env.content.replace(/&/, '&');
|
230 | }
|
231 | });
|
232 |
|
233 | Prism.languages.adoc = Prism.languages.asciidoc;
|
234 | }(Prism));
|