source: node_modules/refractor/lang/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: 8.2 KB
Line 
1'use strict'
2
3module.exports = asciidoc
4asciidoc.displayName = 'asciidoc'
5asciidoc.aliases = ['adoc']
6function asciidoc(Prism) {
7 ;(function (Prism) {
8 var attributes = {
9 pattern:
10 /(^[ \t]*)\[(?!\[)(?:(["'$`])(?:(?!\2)[^\\]|\\.)*\2|\[(?:[^\[\]\\]|\\.)*\]|[^\[\]\\"'$`]|\\.)*\]/m,
11 lookbehind: true,
12 inside: {
13 quoted: {
14 pattern: /([$`])(?:(?!\1)[^\\]|\\.)*\1/,
15 inside: {
16 punctuation: /^[$`]|[$`]$/
17 }
18 },
19 interpreted: {
20 pattern: /'(?:[^'\\]|\\.)*'/,
21 inside: {
22 punctuation: /^'|'$/ // See rest below
23 }
24 },
25 string: /"(?:[^"\\]|\\.)*"/,
26 variable: /\w+(?==)/,
27 punctuation: /^\[|\]$|,/,
28 operator: /=/,
29 // The negative look-ahead prevents blank matches
30 'attr-value': /(?!^\s+$).+/
31 }
32 }
33 var asciidoc = (Prism.languages.asciidoc = {
34 'comment-block': {
35 pattern: /^(\/{4,})(?:\r?\n|\r)(?:[\s\S]*(?:\r?\n|\r))??\1/m,
36 alias: 'comment'
37 },
38 table: {
39 pattern: /^\|={3,}(?:(?:\r?\n|\r(?!\n)).*)*?(?:\r?\n|\r)\|={3,}$/m,
40 inside: {
41 specifiers: {
42 pattern:
43 /(?:(?:(?:\d+(?:\.\d+)?|\.\d+)[+*](?:[<^>](?:\.[<^>])?|\.[<^>])?|[<^>](?:\.[<^>])?|\.[<^>])[a-z]*|[a-z]+)(?=\|)/,
44 alias: 'attr-value'
45 },
46 punctuation: {
47 pattern: /(^|[^\\])[|!]=*/,
48 lookbehind: true
49 } // See rest below
50 }
51 },
52 'passthrough-block': {
53 pattern: /^(\+{4,})(?:\r?\n|\r)(?:[\s\S]*(?:\r?\n|\r))??\1$/m,
54 inside: {
55 punctuation: /^\++|\++$/ // See rest below
56 }
57 },
58 // Literal blocks and listing blocks
59 'literal-block': {
60 pattern: /^(-{4,}|\.{4,})(?:\r?\n|\r)(?:[\s\S]*(?:\r?\n|\r))??\1$/m,
61 inside: {
62 punctuation: /^(?:-+|\.+)|(?:-+|\.+)$/ // See rest below
63 }
64 },
65 // Sidebar blocks, quote blocks, example blocks and open blocks
66 'other-block': {
67 pattern:
68 /^(--|\*{4,}|_{4,}|={4,})(?:\r?\n|\r)(?:[\s\S]*(?:\r?\n|\r))??\1$/m,
69 inside: {
70 punctuation: /^(?:-+|\*+|_+|=+)|(?:-+|\*+|_+|=+)$/ // See rest below
71 }
72 },
73 // list-punctuation and list-label must appear before indented-block
74 'list-punctuation': {
75 pattern:
76 /(^[ \t]*)(?:-|\*{1,5}|\.{1,5}|(?:[a-z]|\d+)\.|[xvi]+\))(?= )/im,
77 lookbehind: true,
78 alias: 'punctuation'
79 },
80 'list-label': {
81 pattern: /(^[ \t]*)[a-z\d].+(?::{2,4}|;;)(?=\s)/im,
82 lookbehind: true,
83 alias: 'symbol'
84 },
85 'indented-block': {
86 pattern: /((\r?\n|\r)\2)([ \t]+)\S.*(?:(?:\r?\n|\r)\3.+)*(?=\2{2}|$)/,
87 lookbehind: true
88 },
89 comment: /^\/\/.*/m,
90 title: {
91 pattern:
92 /^.+(?:\r?\n|\r)(?:={3,}|-{3,}|~{3,}|\^{3,}|\+{3,})$|^={1,5} .+|^\.(?![\s.]).*/m,
93 alias: 'important',
94 inside: {
95 punctuation: /^(?:\.|=+)|(?:=+|-+|~+|\^+|\++)$/ // 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:
128 /\b[a-z\d][a-z\d-]*::?(?:[^\s\[\]]*\[(?:[^\]\\"']|(["'])(?:(?!\1)[^\\]|\\.)*\1|\\.)*\])/,
129 inside: {
130 function: /^[a-z\d-]+(?=:)/,
131 punctuation: /^::?/,
132 attributes: {
133 pattern: /(?:\[(?:[^\]\\"']|(["'])(?:(?!\1)[^\\]|\\.)*\1|\\.)*\])/,
134 inside: attributes.inside
135 }
136 }
137 },
138 inline: {
139 /*
140The initial look-behind prevents the highlighting of escaped quoted text.
141Quoted text can be multi-line but cannot span an empty line.
142All quoted text can have attributes before [foobar, 'foobar', baz="bar"].
143First, we handle the constrained quotes.
144Those must be bounded by non-word chars and cannot have spaces between the delimiter and the first char.
145They are, in order: _emphasis_, ``double quotes'', `single quotes', `monospace`, 'emphasis', *strong*, +monospace+ and #unquoted#
146Then we handle the unconstrained quotes.
147Those do not have the restrictions of the constrained quotes.
148They are, in order: __emphasis__, **strong**, ++monospace++, +++passthrough+++, ##unquoted##, $$passthrough$$, ~subscript~, ^superscript^, {attribute-reference}, [[anchor]], [[[bibliography anchor]]], <<xref>>, (((indexes))) and ((indexes))
149*/
150 pattern:
151 /(^|[^\\])(?:(?:\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,
152 lookbehind: true,
153 inside: {
154 attributes: attributes,
155 url: {
156 pattern: /^(?:\[\[\[?.+?\]?\]\]|<<.+?>>)$/,
157 inside: {
158 punctuation: /^(?:\[\[\[?|<<)|(?:\]\]\]?|>>)$/
159 }
160 },
161 'attribute-ref': {
162 pattern: /^\{.+\}$/,
163 inside: {
164 variable: {
165 pattern: /(^\{)[a-z\d,+_-]+/,
166 lookbehind: true
167 },
168 operator: /^[=?!#%@$]|!(?=[:}])/,
169 punctuation: /^\{|\}$|::?/
170 }
171 },
172 italic: {
173 pattern: /^(['_])[\s\S]+\1$/,
174 inside: {
175 punctuation: /^(?:''?|__?)|(?:''?|__?)$/
176 }
177 },
178 bold: {
179 pattern: /^\*[\s\S]+\*$/,
180 inside: {
181 punctuation: /^\*\*?|\*\*?$/
182 }
183 },
184 punctuation:
185 /^(?:``?|\+{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 }) // Allow some nesting. There is no recursion though, so cloning should not be needed.
199 function copyFromAsciiDoc(keys) {
200 keys = keys.split(' ')
201 var o = {}
202 for (var i = 0, l = keys.length; i < l; i++) {
203 o[keys[i]] = asciidoc[keys[i]]
204 }
205 return o
206 }
207 attributes.inside['interpreted'].inside.rest = copyFromAsciiDoc(
208 'macro inline replacement entity'
209 )
210 asciidoc['passthrough-block'].inside.rest = copyFromAsciiDoc('macro')
211 asciidoc['literal-block'].inside.rest = copyFromAsciiDoc('callout')
212 asciidoc['table'].inside.rest = copyFromAsciiDoc(
213 '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'
214 )
215 asciidoc['other-block'].inside.rest = copyFromAsciiDoc(
216 'table list-punctuation indented-block comment attribute-entry attributes hr page-break admonition list-label macro inline replacement entity line-continuation'
217 )
218 asciidoc['title'].inside.rest = copyFromAsciiDoc(
219 'macro inline replacement entity'
220 ) // Plugin to make entity title show the real entity, idea by Roman Komarov
221 Prism.hooks.add('wrap', function (env) {
222 if (env.type === 'entity') {
223 env.attributes['title'] = env.content.value.replace(/&amp;/, '&')
224 }
225 })
226 Prism.languages.adoc = Prism.languages.asciidoc
227 })(Prism)
228}
Note: See TracBrowser for help on using the repository browser.