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 | // See rest below
|
---|
18 | }
|
---|
19 | },
|
---|
20 | 'string': /"(?:[^"\\]|\\.)*"/,
|
---|
21 | 'variable': /\w+(?==)/,
|
---|
22 | 'punctuation': /^\[|\]$|,/,
|
---|
23 | 'operator': /=/,
|
---|
24 | // The negative look-ahead prevents blank matches
|
---|
25 | 'attr-value': /(?!^\s+$).+/
|
---|
26 | }
|
---|
27 | };
|
---|
28 |
|
---|
29 | var asciidoc = Prism.languages.asciidoc = {
|
---|
30 | 'comment-block': {
|
---|
31 | pattern: /^(\/{4,})$[\s\S]*?^\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 | // See rest below
|
---|
46 | }
|
---|
47 | },
|
---|
48 |
|
---|
49 | 'passthrough-block': {
|
---|
50 | pattern: /^(\+{4,})$[\s\S]*?^\1$/m,
|
---|
51 | inside: {
|
---|
52 | 'punctuation': /^\++|\++$/
|
---|
53 | // See rest below
|
---|
54 | }
|
---|
55 | },
|
---|
56 | // Literal blocks and listing blocks
|
---|
57 | 'literal-block': {
|
---|
58 | pattern: /^(-{4,}|\.{4,})$[\s\S]*?^\1$/m,
|
---|
59 | inside: {
|
---|
60 | 'punctuation': /^(?:-+|\.+)|(?:-+|\.+)$/
|
---|
61 | // See rest below
|
---|
62 | }
|
---|
63 | },
|
---|
64 | // Sidebar blocks, quote blocks, example blocks and open blocks
|
---|
65 | 'other-block': {
|
---|
66 | pattern: /^(--|\*{4,}|_{4,}|={4,})$[\s\S]*?^\1$/m,
|
---|
67 | inside: {
|
---|
68 | 'punctuation': /^(?:-+|\*+|_+|=+)|(?:-+|\*+|_+|=+)$/
|
---|
69 | // See rest below
|
---|
70 | }
|
---|
71 | },
|
---|
72 |
|
---|
73 | // list-punctuation and list-label must appear before indented-block
|
---|
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 | // See rest below
|
---|
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: /^(?:CAUTION|IMPORTANT|NOTE|TIP|WARNING):/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 | The initial look-behind prevents the highlighting of escaped quoted text.
|
---|
140 |
|
---|
141 | Quoted text can be multi-line but cannot span an empty line.
|
---|
142 | All quoted text can have attributes before [foobar, 'foobar', baz="bar"].
|
---|
143 |
|
---|
144 | First, we handle the constrained quotes.
|
---|
145 | Those must be bounded by non-word chars and cannot have spaces between the delimiter and the first char.
|
---|
146 | They are, in order: _emphasis_, ``double quotes'', `single quotes', `monospace`, 'emphasis', *strong*, +monospace+ and #unquoted#
|
---|
147 |
|
---|
148 | Then we handle the unconstrained quotes.
|
---|
149 | Those do not have the restrictions of the constrained quotes.
|
---|
150 | They are, in order: __emphasis__, **strong**, ++monospace++, +++passthrough+++, ##unquoted##, $$passthrough$$, ~subscript~, ^superscript^, {attribute-reference}, [[anchor]], [[[bibliography anchor]]], <<xref>>, (((indexes))) and ((indexes))
|
---|
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|R|TM)\)/,
|
---|
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 | // Allow some nesting. There is no recursion though, so cloning should not be needed.
|
---|
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 | // Plugin to make entity title show the real entity, idea by Roman Komarov
|
---|
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));
|
---|