1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | const core = require('./core-96a5dc61.js');
|
6 |
|
7 | var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
8 |
|
9 | function createCommonjsModule(fn, module) {
|
10 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
11 | }
|
12 |
|
13 | var marked = createCommonjsModule(function (module, exports) {
|
14 | (function(root) {
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | var block = {
|
21 | newline: /^\n+/,
|
22 | code: /^( {4}[^\n]+\n*)+/,
|
23 | fences: noop,
|
24 | hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
|
25 | heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
|
26 | nptable: noop,
|
27 | blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
|
28 | list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
|
29 | html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
|
30 | def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
|
31 | table: noop,
|
32 | lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
|
33 | paragraph: /^([^\n]+(?:\n?(?!hr|heading|lheading| {0,3}>|tag)[^\n]+)+)/,
|
34 | text: /^[^\n]+/
|
35 | };
|
36 |
|
37 | block._label = /(?:\\[\[\]]|[^\[\]])+/;
|
38 | block._title = /(?:"(?:\\"|[^"]|"[^"\n]*")*"|'\n?(?:[^'\n]+\n?)*'|\([^()]*\))/;
|
39 | block.def = edit(block.def)
|
40 | .replace('label', block._label)
|
41 | .replace('title', block._title)
|
42 | .getRegex();
|
43 |
|
44 | block.bullet = /(?:[*+-]|\d+\.)/;
|
45 | block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
|
46 | block.item = edit(block.item, 'gm')
|
47 | .replace(/bull/g, block.bullet)
|
48 | .getRegex();
|
49 |
|
50 | block.list = edit(block.list)
|
51 | .replace(/bull/g, block.bullet)
|
52 | .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
|
53 | .replace('def', '\\n+(?=' + block.def.source + ')')
|
54 | .getRegex();
|
55 |
|
56 | block._tag = '(?!(?:'
|
57 | + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
|
58 | + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
|
59 | + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b';
|
60 |
|
61 | block.html = edit(block.html)
|
62 | .replace('comment', //)
|
63 | .replace('closed', /<(tag)[\s\S]+?<\/\1>/)
|
64 | .replace('closing', /<tag(?:"[^"]*"|'[^']*'|\s[^'"\/>\s]*)*?\/?>/)
|
65 | .replace(/tag/g, block._tag)
|
66 | .getRegex();
|
67 |
|
68 | block.paragraph = edit(block.paragraph)
|
69 | .replace('hr', block.hr)
|
70 | .replace('heading', block.heading)
|
71 | .replace('lheading', block.lheading)
|
72 | .replace('tag', '<' + block._tag)
|
73 | .getRegex();
|
74 |
|
75 | block.blockquote = edit(block.blockquote)
|
76 | .replace('paragraph', block.paragraph)
|
77 | .getRegex();
|
78 |
|
79 | /**
|
80 | * Normal Block Grammar
|
81 | */
|
82 |
|
83 | block.normal = merge({}, block);
|
84 |
|
85 | /**
|
86 | * GFM Block Grammar
|
87 | */
|
88 |
|
89 | block.gfm = merge({}, block.normal, {
|
90 | fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\n? *\1 *(?:\n+|$)/,
|
91 | paragraph: /^/,
|
92 | heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
|
93 | });
|
94 |
|
95 | block.gfm.paragraph = edit(block.paragraph)
|
96 | .replace('(?!', '(?!'
|
97 | + block.gfm.fences.source.replace('\\1', '\\2') + '|'
|
98 | + block.list.source.replace('\\1', '\\3') + '|')
|
99 | .getRegex();
|
100 |
|
101 | /**
|
102 | * GFM + Tables Block Grammar
|
103 | */
|
104 |
|
105 | block.tables = merge({}, block.gfm, {
|
106 | nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
|
107 | table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
|
108 | });
|
109 |
|
110 | /**
|
111 | * Block Lexer
|
112 | */
|
113 |
|
114 | function Lexer(options) {
|
115 | this.tokens = [];
|
116 | this.tokens.links = {};
|
117 | this.options = options || marked.defaults;
|
118 | this.rules = block.normal;
|
119 |
|
120 | if (this.options.gfm) {
|
121 | if (this.options.tables) {
|
122 | this.rules = block.tables;
|
123 | } else {
|
124 | this.rules = block.gfm;
|
125 | }
|
126 | }
|
127 | }
|
128 |
|
129 | /**
|
130 | * Expose Block Rules
|
131 | */
|
132 |
|
133 | Lexer.rules = block;
|
134 |
|
135 | /**
|
136 | * Static Lex Method
|
137 | */
|
138 |
|
139 | Lexer.lex = function(src, options) {
|
140 | var lexer = new Lexer(options);
|
141 | return lexer.lex(src);
|
142 | };
|
143 |
|
144 | /**
|
145 | * Preprocessing
|
146 | */
|
147 |
|
148 | Lexer.prototype.lex = function(src) {
|
149 | src = src
|
150 | .replace(/\r\n|\r/g, '\n')
|
151 | .replace(/\t/g, ' ')
|
152 | .replace(/\u00a0/g, ' ')
|
153 | .replace(/\u2424/g, '\n');
|
154 |
|
155 | return this.token(src, true);
|
156 | };
|
157 |
|
158 | /**
|
159 | * Lexing
|
160 | */
|
161 |
|
162 | Lexer.prototype.token = function(src, top) {
|
163 | src = src.replace(/^ +$/gm, '');
|
164 | var next,
|
165 | loose,
|
166 | cap,
|
167 | bull,
|
168 | b,
|
169 | item,
|
170 | space,
|
171 | i,
|
172 | tag,
|
173 | l,
|
174 | isordered;
|
175 |
|
176 | while (src) {
|
177 | // newline
|
178 | if (cap = this.rules.newline.exec(src)) {
|
179 | src = src.substring(cap[0].length);
|
180 | if (cap[0].length > 1) {
|
181 | this.tokens.push({
|
182 | type: 'space'
|
183 | });
|
184 | }
|
185 | }
|
186 |
|
187 | // code
|
188 | if (cap = this.rules.code.exec(src)) {
|
189 | src = src.substring(cap[0].length);
|
190 | cap = cap[0].replace(/^ {4}/gm, '');
|
191 | this.tokens.push({
|
192 | type: 'code',
|
193 | text: !this.options.pedantic
|
194 | ? cap.replace(/\n+$/, '')
|
195 | : cap
|
196 | });
|
197 | continue;
|
198 | }
|
199 |
|
200 | // fences (gfm)
|
201 | if (cap = this.rules.fences.exec(src)) {
|
202 | src = src.substring(cap[0].length);
|
203 | this.tokens.push({
|
204 | type: 'code',
|
205 | lang: cap[2],
|
206 | text: cap[3] || ''
|
207 | });
|
208 | continue;
|
209 | }
|
210 |
|
211 | // heading
|
212 | if (cap = this.rules.heading.exec(src)) {
|
213 | src = src.substring(cap[0].length);
|
214 | this.tokens.push({
|
215 | type: 'heading',
|
216 | depth: cap[1].length,
|
217 | text: cap[2]
|
218 | });
|
219 | continue;
|
220 | }
|
221 |
|
222 | // table no leading pipe (gfm)
|
223 | if (top && (cap = this.rules.nptable.exec(src))) {
|
224 | src = src.substring(cap[0].length);
|
225 |
|
226 | item = {
|
227 | type: 'table',
|
228 | header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
|
229 | align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
230 | cells: cap[3].replace(/\n$/, '').split('\n')
|
231 | };
|
232 |
|
233 | for (i = 0; i < item.align.length; i++) {
|
234 | if (/^ *-+: *$/.test(item.align[i])) {
|
235 | item.align[i] = 'right';
|
236 | } else if (/^ *:-+: *$/.test(item.align[i])) {
|
237 | item.align[i] = 'center';
|
238 | } else if (/^ *:-+ *$/.test(item.align[i])) {
|
239 | item.align[i] = 'left';
|
240 | } else {
|
241 | item.align[i] = null;
|
242 | }
|
243 | }
|
244 |
|
245 | for (i = 0; i < item.cells.length; i++) {
|
246 | item.cells[i] = item.cells[i].split(/ *\| */);
|
247 | }
|
248 |
|
249 | this.tokens.push(item);
|
250 |
|
251 | continue;
|
252 | }
|
253 |
|
254 | // hr
|
255 | if (cap = this.rules.hr.exec(src)) {
|
256 | src = src.substring(cap[0].length);
|
257 | this.tokens.push({
|
258 | type: 'hr'
|
259 | });
|
260 | continue;
|
261 | }
|
262 |
|
263 | // blockquote
|
264 | if (cap = this.rules.blockquote.exec(src)) {
|
265 | src = src.substring(cap[0].length);
|
266 |
|
267 | this.tokens.push({
|
268 | type: 'blockquote_start'
|
269 | });
|
270 |
|
271 | cap = cap[0].replace(/^ *> ?/gm, '');
|
272 |
|
273 | // Pass `top` to keep the current
|
274 | // "toplevel" state. This is exactly
|
275 | // how markdown.pl works.
|
276 | this.token(cap, top);
|
277 |
|
278 | this.tokens.push({
|
279 | type: 'blockquote_end'
|
280 | });
|
281 |
|
282 | continue;
|
283 | }
|
284 |
|
285 | // list
|
286 | if (cap = this.rules.list.exec(src)) {
|
287 | src = src.substring(cap[0].length);
|
288 | bull = cap[2];
|
289 | isordered = bull.length > 1;
|
290 |
|
291 | this.tokens.push({
|
292 | type: 'list_start',
|
293 | ordered: isordered,
|
294 | start: isordered ? +bull : ''
|
295 | });
|
296 |
|
297 | // Get each top-level item.
|
298 | cap = cap[0].match(this.rules.item);
|
299 |
|
300 | next = false;
|
301 | l = cap.length;
|
302 | i = 0;
|
303 |
|
304 | for (; i < l; i++) {
|
305 | item = cap[i];
|
306 |
|
307 | // Remove the list item's bullet
|
308 | // so it is seen as the next token.
|
309 | space = item.length;
|
310 | item = item.replace(/^ *([*+-]|\d+\.) +/, '');
|
311 |
|
312 | // Outdent whatever the
|
313 | // list item contains. Hacky.
|
314 | if (~item.indexOf('\n ')) {
|
315 | space -= item.length;
|
316 | item = !this.options.pedantic
|
317 | ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
|
318 | : item.replace(/^ {1,4}/gm, '');
|
319 | }
|
320 |
|
321 | // Determine whether the next list item belongs here.
|
322 | // Backpedal if it does not belong in this list.
|
323 | if (this.options.smartLists && i !== l - 1) {
|
324 | b = block.bullet.exec(cap[i + 1])[0];
|
325 | if (bull !== b && !(bull.length > 1 && b.length > 1)) {
|
326 | src = cap.slice(i + 1).join('\n') + src;
|
327 | i = l - 1;
|
328 | }
|
329 | }
|
330 |
|
331 | // Determine whether item is loose or not.
|
332 | // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
|
333 | // for discount behavior.
|
334 | loose = next || /\n\n(?!\s*$)/.test(item);
|
335 | if (i !== l - 1) {
|
336 | next = item.charAt(item.length - 1) === '\n';
|
337 | if (!loose) loose = next;
|
338 | }
|
339 |
|
340 | this.tokens.push({
|
341 | type: loose
|
342 | ? 'loose_item_start'
|
343 | : 'list_item_start'
|
344 | });
|
345 |
|
346 | // Recurse.
|
347 | this.token(item, false);
|
348 |
|
349 | this.tokens.push({
|
350 | type: 'list_item_end'
|
351 | });
|
352 | }
|
353 |
|
354 | this.tokens.push({
|
355 | type: 'list_end'
|
356 | });
|
357 |
|
358 | continue;
|
359 | }
|
360 |
|
361 | // html
|
362 | if (cap = this.rules.html.exec(src)) {
|
363 | src = src.substring(cap[0].length);
|
364 | this.tokens.push({
|
365 | type: this.options.sanitize
|
366 | ? 'paragraph'
|
367 | : 'html',
|
368 | pre: !this.options.sanitizer
|
369 | && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
|
370 | text: cap[0]
|
371 | });
|
372 | continue;
|
373 | }
|
374 |
|
375 | // def
|
376 | if (top && (cap = this.rules.def.exec(src))) {
|
377 | src = src.substring(cap[0].length);
|
378 | if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
|
379 | tag = cap[1].toLowerCase();
|
380 | if (!this.tokens.links[tag]) {
|
381 | this.tokens.links[tag] = {
|
382 | href: cap[2],
|
383 | title: cap[3]
|
384 | };
|
385 | }
|
386 | continue;
|
387 | }
|
388 |
|
389 | // table (gfm)
|
390 | if (top && (cap = this.rules.table.exec(src))) {
|
391 | src = src.substring(cap[0].length);
|
392 |
|
393 | item = {
|
394 | type: 'table',
|
395 | header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
|
396 | align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
397 | cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
|
398 | };
|
399 |
|
400 | for (i = 0; i < item.align.length; i++) {
|
401 | if (/^ *-+: *$/.test(item.align[i])) {
|
402 | item.align[i] = 'right';
|
403 | } else if (/^ *:-+: *$/.test(item.align[i])) {
|
404 | item.align[i] = 'center';
|
405 | } else if (/^ *:-+ *$/.test(item.align[i])) {
|
406 | item.align[i] = 'left';
|
407 | } else {
|
408 | item.align[i] = null;
|
409 | }
|
410 | }
|
411 |
|
412 | for (i = 0; i < item.cells.length; i++) {
|
413 | item.cells[i] = item.cells[i]
|
414 | .replace(/^ *\| *| *\| *$/g, '')
|
415 | .split(/ *\| */);
|
416 | }
|
417 |
|
418 | this.tokens.push(item);
|
419 |
|
420 | continue;
|
421 | }
|
422 |
|
423 | // lheading
|
424 | if (cap = this.rules.lheading.exec(src)) {
|
425 | src = src.substring(cap[0].length);
|
426 | this.tokens.push({
|
427 | type: 'heading',
|
428 | depth: cap[2] === '=' ? 1 : 2,
|
429 | text: cap[1]
|
430 | });
|
431 | continue;
|
432 | }
|
433 |
|
434 | // top-level paragraph
|
435 | if (top && (cap = this.rules.paragraph.exec(src))) {
|
436 | src = src.substring(cap[0].length);
|
437 | this.tokens.push({
|
438 | type: 'paragraph',
|
439 | text: cap[1].charAt(cap[1].length - 1) === '\n'
|
440 | ? cap[1].slice(0, -1)
|
441 | : cap[1]
|
442 | });
|
443 | continue;
|
444 | }
|
445 |
|
446 | // text
|
447 | if (cap = this.rules.text.exec(src)) {
|
448 | // Top-level should never reach here.
|
449 | src = src.substring(cap[0].length);
|
450 | this.tokens.push({
|
451 | type: 'text',
|
452 | text: cap[0]
|
453 | });
|
454 | continue;
|
455 | }
|
456 |
|
457 | if (src) {
|
458 | throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
|
459 | }
|
460 | }
|
461 |
|
462 | return this.tokens;
|
463 | };
|
464 |
|
465 | /**
|
466 | * Inline-Level Grammar
|
467 | */
|
468 |
|
469 | var inline = {
|
470 | escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
|
471 | autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
|
472 | url: noop,
|
473 | tag: /^<!--[\s\S]*?-->|^<\/?[a-zA-Z0-9\-]+(?:"[^"]*"|'[^']*'|\s[^<'">\/\s]*)*?\/?>/,
|
474 | link: /^!?\[(inside)\]\(href\)/,
|
475 | reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
|
476 | nolink: /^!?\[((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
|
477 | strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
|
478 | em: /^_([^\s_](?:[^_]|__)+?[^\s_])_\b|^\*((?:\*\*|[^*])+?)\*(?!\*)/,
|
479 | code: /^(`+)\s*([\s\S]*?[^`]?)\s*\1(?!`)/,
|
480 | br: /^ {2,}\n(?!\s*$)/,
|
481 | del: noop,
|
482 | text: /^[\s\S]+?(?=[\\<!\[`*]|\b_| {2,}\n|$)/
|
483 | };
|
484 |
|
485 | inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
|
486 | inline._email = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;
|
487 |
|
488 | inline.autolink = edit(inline.autolink)
|
489 | .replace('scheme', inline._scheme)
|
490 | .replace('email', inline._email)
|
491 | .getRegex();
|
492 |
|
493 | inline._inside = /(?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]]|\](?=[^\[]*\]))*/;
|
494 | inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
|
495 |
|
496 | inline.link = edit(inline.link)
|
497 | .replace('inside', inline._inside)
|
498 | .replace('href', inline._href)
|
499 | .getRegex();
|
500 |
|
501 | inline.reflink = edit(inline.reflink)
|
502 | .replace('inside', inline._inside)
|
503 | .getRegex();
|
504 |
|
505 | /**
|
506 | * Normal Inline Grammar
|
507 | */
|
508 |
|
509 | inline.normal = merge({}, inline);
|
510 |
|
511 | /**
|
512 | * Pedantic Inline Grammar
|
513 | */
|
514 |
|
515 | inline.pedantic = merge({}, inline.normal, {
|
516 | strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
|
517 | em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
|
518 | });
|
519 |
|
520 | /**
|
521 | * GFM Inline Grammar
|
522 | */
|
523 |
|
524 | inline.gfm = merge({}, inline.normal, {
|
525 | escape: edit(inline.escape).replace('])', '~|])').getRegex(),
|
526 | url: edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/)
|
527 | .replace('email', inline._email)
|
528 | .getRegex(),
|
529 | _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
|
530 | del: /^~~(?=\S)([\s\S]*?\S)~~/,
|
531 | text: edit(inline.text)
|
532 | .replace(']|', '~]|')
|
533 | .replace('|', '|https?://|ftp://|www\\.|[a-zA-Z0-9.!#$%&\'*+/=?^_`{\\|}~-]+@|')
|
534 | .getRegex()
|
535 | });
|
536 |
|
537 | /**
|
538 | * GFM + Line Breaks Inline Grammar
|
539 | */
|
540 |
|
541 | inline.breaks = merge({}, inline.gfm, {
|
542 | br: edit(inline.br).replace('{2,}', '*').getRegex(),
|
543 | text: edit(inline.gfm.text).replace('{2,}', '*').getRegex()
|
544 | });
|
545 |
|
546 | /**
|
547 | * Inline Lexer & Compiler
|
548 | */
|
549 |
|
550 | function InlineLexer(links, options) {
|
551 | this.options = options || marked.defaults;
|
552 | this.links = links;
|
553 | this.rules = inline.normal;
|
554 | this.renderer = this.options.renderer || new Renderer();
|
555 | this.renderer.options = this.options;
|
556 |
|
557 | if (!this.links) {
|
558 | throw new Error('Tokens array requires a `links` property.');
|
559 | }
|
560 |
|
561 | if (this.options.gfm) {
|
562 | if (this.options.breaks) {
|
563 | this.rules = inline.breaks;
|
564 | } else {
|
565 | this.rules = inline.gfm;
|
566 | }
|
567 | } else if (this.options.pedantic) {
|
568 | this.rules = inline.pedantic;
|
569 | }
|
570 | }
|
571 |
|
572 | /**
|
573 | * Expose Inline Rules
|
574 | */
|
575 |
|
576 | InlineLexer.rules = inline;
|
577 |
|
578 | /**
|
579 | * Static Lexing/Compiling Method
|
580 | */
|
581 |
|
582 | InlineLexer.output = function(src, links, options) {
|
583 | var inline = new InlineLexer(links, options);
|
584 | return inline.output(src);
|
585 | };
|
586 |
|
587 | /**
|
588 | * Lexing/Compiling
|
589 | */
|
590 |
|
591 | InlineLexer.prototype.output = function(src) {
|
592 | var out = '',
|
593 | link,
|
594 | text,
|
595 | href,
|
596 | cap;
|
597 |
|
598 | while (src) {
|
599 | // escape
|
600 | if (cap = this.rules.escape.exec(src)) {
|
601 | src = src.substring(cap[0].length);
|
602 | out += cap[1];
|
603 | continue;
|
604 | }
|
605 |
|
606 | // autolink
|
607 | if (cap = this.rules.autolink.exec(src)) {
|
608 | src = src.substring(cap[0].length);
|
609 | if (cap[2] === '@') {
|
610 | text = escape(this.mangle(cap[1]));
|
611 | href = 'mailto:' + text;
|
612 | } else {
|
613 | text = escape(cap[1]);
|
614 | href = text;
|
615 | }
|
616 | out += this.renderer.link(href, null, text);
|
617 | continue;
|
618 | }
|
619 |
|
620 | // url (gfm)
|
621 | if (!this.inLink && (cap = this.rules.url.exec(src))) {
|
622 | cap[0] = this.rules._backpedal.exec(cap[0])[0];
|
623 | src = src.substring(cap[0].length);
|
624 | if (cap[2] === '@') {
|
625 | text = escape(cap[0]);
|
626 | href = 'mailto:' + text;
|
627 | } else {
|
628 | text = escape(cap[0]);
|
629 | if (cap[1] === 'www.') {
|
630 | href = 'http://' + text;
|
631 | } else {
|
632 | href = text;
|
633 | }
|
634 | }
|
635 | out += this.renderer.link(href, null, text);
|
636 | continue;
|
637 | }
|
638 |
|
639 | // tag
|
640 | if (cap = this.rules.tag.exec(src)) {
|
641 | if (!this.inLink && /^<a /i.test(cap[0])) {
|
642 | this.inLink = true;
|
643 | } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
|
644 | this.inLink = false;
|
645 | }
|
646 | src = src.substring(cap[0].length);
|
647 | out += this.options.sanitize
|
648 | ? this.options.sanitizer
|
649 | ? this.options.sanitizer(cap[0])
|
650 | : escape(cap[0])
|
651 | : cap[0];
|
652 | continue;
|
653 | }
|
654 |
|
655 | // link
|
656 | if (cap = this.rules.link.exec(src)) {
|
657 | src = src.substring(cap[0].length);
|
658 | this.inLink = true;
|
659 | out += this.outputLink(cap, {
|
660 | href: cap[2],
|
661 | title: cap[3]
|
662 | });
|
663 | this.inLink = false;
|
664 | continue;
|
665 | }
|
666 |
|
667 | // reflink, nolink
|
668 | if ((cap = this.rules.reflink.exec(src))
|
669 | || (cap = this.rules.nolink.exec(src))) {
|
670 | src = src.substring(cap[0].length);
|
671 | link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
|
672 | link = this.links[link.toLowerCase()];
|
673 | if (!link || !link.href) {
|
674 | out += cap[0].charAt(0);
|
675 | src = cap[0].substring(1) + src;
|
676 | continue;
|
677 | }
|
678 | this.inLink = true;
|
679 | out += this.outputLink(cap, link);
|
680 | this.inLink = false;
|
681 | continue;
|
682 | }
|
683 |
|
684 | // strong
|
685 | if (cap = this.rules.strong.exec(src)) {
|
686 | src = src.substring(cap[0].length);
|
687 | out += this.renderer.strong(this.output(cap[2] || cap[1]));
|
688 | continue;
|
689 | }
|
690 |
|
691 | // em
|
692 | if (cap = this.rules.em.exec(src)) {
|
693 | src = src.substring(cap[0].length);
|
694 | out += this.renderer.em(this.output(cap[2] || cap[1]));
|
695 | continue;
|
696 | }
|
697 |
|
698 | // code
|
699 | if (cap = this.rules.code.exec(src)) {
|
700 | src = src.substring(cap[0].length);
|
701 | out += this.renderer.codespan(escape(cap[2].trim(), true));
|
702 | continue;
|
703 | }
|
704 |
|
705 | // br
|
706 | if (cap = this.rules.br.exec(src)) {
|
707 | src = src.substring(cap[0].length);
|
708 | out += this.renderer.br();
|
709 | continue;
|
710 | }
|
711 |
|
712 | // del (gfm)
|
713 | if (cap = this.rules.del.exec(src)) {
|
714 | src = src.substring(cap[0].length);
|
715 | out += this.renderer.del(this.output(cap[1]));
|
716 | continue;
|
717 | }
|
718 |
|
719 | // text
|
720 | if (cap = this.rules.text.exec(src)) {
|
721 | src = src.substring(cap[0].length);
|
722 | out += this.renderer.text(escape(this.smartypants(cap[0])));
|
723 | continue;
|
724 | }
|
725 |
|
726 | if (src) {
|
727 | throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
|
728 | }
|
729 | }
|
730 |
|
731 | return out;
|
732 | };
|
733 |
|
734 | /**
|
735 | * Compile Link
|
736 | */
|
737 |
|
738 | InlineLexer.prototype.outputLink = function(cap, link) {
|
739 | var href = escape(link.href),
|
740 | title = link.title ? escape(link.title) : null;
|
741 |
|
742 | return cap[0].charAt(0) !== '!'
|
743 | ? this.renderer.link(href, title, this.output(cap[1]))
|
744 | : this.renderer.image(href, title, escape(cap[1]));
|
745 | };
|
746 |
|
747 | /**
|
748 | * Smartypants Transformations
|
749 | */
|
750 |
|
751 | InlineLexer.prototype.smartypants = function(text) {
|
752 | if (!this.options.smartypants) return text;
|
753 | return text
|
754 | // em-dashes
|
755 | .replace(/---/g, '\u2014')
|
756 | // en-dashes
|
757 | .replace(/--/g, '\u2013')
|
758 | // opening singles
|
759 | .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
|
760 | // closing singles & apostrophes
|
761 | .replace(/'/g, '\u2019')
|
762 | // opening doubles
|
763 | .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
|
764 | // closing doubles
|
765 | .replace(/"/g, '\u201d')
|
766 | // ellipses
|
767 | .replace(/\.{3}/g, '\u2026');
|
768 | };
|
769 |
|
770 | /**
|
771 | * Mangle Links
|
772 | */
|
773 |
|
774 | InlineLexer.prototype.mangle = function(text) {
|
775 | if (!this.options.mangle) return text;
|
776 | var out = '',
|
777 | l = text.length,
|
778 | i = 0,
|
779 | ch;
|
780 |
|
781 | for (; i < l; i++) {
|
782 | ch = text.charCodeAt(i);
|
783 | if (Math.random() > 0.5) {
|
784 | ch = 'x' + ch.toString(16);
|
785 | }
|
786 | out += '&#' + ch + ';';
|
787 | }
|
788 |
|
789 | return out;
|
790 | };
|
791 |
|
792 | /**
|
793 | * Renderer
|
794 | */
|
795 |
|
796 | function Renderer(options) {
|
797 | this.options = options || {};
|
798 | }
|
799 |
|
800 | Renderer.prototype.code = function(code, lang, escaped) {
|
801 | if (this.options.highlight) {
|
802 | var out = this.options.highlight(code, lang);
|
803 | if (out != null && out !== code) {
|
804 | escaped = true;
|
805 | code = out;
|
806 | }
|
807 | }
|
808 |
|
809 | if (!lang) {
|
810 | return '<pre><code>'
|
811 | + (escaped ? code : escape(code, true))
|
812 | + '\n</code></pre>';
|
813 | }
|
814 |
|
815 | return '<pre><code class="'
|
816 | + this.options.langPrefix
|
817 | + escape(lang, true)
|
818 | + '">'
|
819 | + (escaped ? code : escape(code, true))
|
820 | + '\n</code></pre>\n';
|
821 | };
|
822 |
|
823 | Renderer.prototype.blockquote = function(quote) {
|
824 | return '<blockquote>\n' + quote + '</blockquote>\n';
|
825 | };
|
826 |
|
827 | Renderer.prototype.html = function(html) {
|
828 | return html;
|
829 | };
|
830 |
|
831 | Renderer.prototype.heading = function(text, level, raw) {
|
832 | return '<h'
|
833 | + level
|
834 | + ' id="'
|
835 | + this.options.headerPrefix
|
836 | + raw.toLowerCase().replace(/[^\w]+/g, '-')
|
837 | + '">'
|
838 | + text
|
839 | + '</h'
|
840 | + level
|
841 | + '>\n';
|
842 | };
|
843 |
|
844 | Renderer.prototype.hr = function() {
|
845 | return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
|
846 | };
|
847 |
|
848 | Renderer.prototype.list = function(body, ordered, start) {
|
849 | var type = ordered ? 'ol' : 'ul',
|
850 | startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
|
851 | return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
|
852 | };
|
853 |
|
854 | Renderer.prototype.listitem = function(text) {
|
855 | return '<li>' + text + '</li>\n';
|
856 | };
|
857 |
|
858 | Renderer.prototype.paragraph = function(text) {
|
859 | return '<p>' + text + '</p>\n';
|
860 | };
|
861 |
|
862 | Renderer.prototype.table = function(header, body) {
|
863 | return '<table>\n'
|
864 | + '<thead>\n'
|
865 | + header
|
866 | + '</thead>\n'
|
867 | + '<tbody>\n'
|
868 | + body
|
869 | + '</tbody>\n'
|
870 | + '</table>\n';
|
871 | };
|
872 |
|
873 | Renderer.prototype.tablerow = function(content) {
|
874 | return '<tr>\n' + content + '</tr>\n';
|
875 | };
|
876 |
|
877 | Renderer.prototype.tablecell = function(content, flags) {
|
878 | var type = flags.header ? 'th' : 'td';
|
879 | var tag = flags.align
|
880 | ? '<' + type + ' style="text-align:' + flags.align + '">'
|
881 | : '<' + type + '>';
|
882 | return tag + content + '</' + type + '>\n';
|
883 | };
|
884 |
|
885 | // span level renderer
|
886 | Renderer.prototype.strong = function(text) {
|
887 | return '<strong>' + text + '</strong>';
|
888 | };
|
889 |
|
890 | Renderer.prototype.em = function(text) {
|
891 | return '<em>' + text + '</em>';
|
892 | };
|
893 |
|
894 | Renderer.prototype.codespan = function(text) {
|
895 | return '<code>' + text + '</code>';
|
896 | };
|
897 |
|
898 | Renderer.prototype.br = function() {
|
899 | return this.options.xhtml ? '<br/>' : '<br>';
|
900 | };
|
901 |
|
902 | Renderer.prototype.del = function(text) {
|
903 | return '<del>' + text + '</del>';
|
904 | };
|
905 |
|
906 | Renderer.prototype.link = function(href, title, text) {
|
907 | if (this.options.sanitize) {
|
908 | try {
|
909 | var prot = decodeURIComponent(unescape(href))
|
910 | .replace(/[^\w:]/g, '')
|
911 | .toLowerCase();
|
912 | } catch (e) {
|
913 | return text;
|
914 | }
|
915 | if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
|
916 | return text;
|
917 | }
|
918 | }
|
919 | if (this.options.baseUrl && !originIndependentUrl.test(href)) {
|
920 | href = resolveUrl(this.options.baseUrl, href);
|
921 | }
|
922 | var out = '<a href="' + href + '"';
|
923 | if (title) {
|
924 | out += ' title="' + title + '"';
|
925 | }
|
926 | out += '>' + text + '</a>';
|
927 | return out;
|
928 | };
|
929 |
|
930 | Renderer.prototype.image = function(href, title, text) {
|
931 | if (this.options.baseUrl && !originIndependentUrl.test(href)) {
|
932 | href = resolveUrl(this.options.baseUrl, href);
|
933 | }
|
934 | var out = '<img src="' + href + '" alt="' + text + '"';
|
935 | if (title) {
|
936 | out += ' title="' + title + '"';
|
937 | }
|
938 | out += this.options.xhtml ? '/>' : '>';
|
939 | return out;
|
940 | };
|
941 |
|
942 | Renderer.prototype.text = function(text) {
|
943 | return text;
|
944 | };
|
945 |
|
946 | /**
|
947 | * TextRenderer
|
948 | * returns only the textual part of the token
|
949 | */
|
950 |
|
951 | function TextRenderer() {}
|
952 |
|
953 | // no need for block level renderers
|
954 |
|
955 | TextRenderer.prototype.strong =
|
956 | TextRenderer.prototype.em =
|
957 | TextRenderer.prototype.codespan =
|
958 | TextRenderer.prototype.del =
|
959 | TextRenderer.prototype.text = function (text) {
|
960 | return text;
|
961 | };
|
962 |
|
963 | TextRenderer.prototype.link =
|
964 | TextRenderer.prototype.image = function(href, title, text) {
|
965 | return '' + text;
|
966 | };
|
967 |
|
968 | TextRenderer.prototype.br = function() {
|
969 | return '';
|
970 | };
|
971 |
|
972 | /**
|
973 | * Parsing & Compiling
|
974 | */
|
975 |
|
976 | function Parser(options) {
|
977 | this.tokens = [];
|
978 | this.token = null;
|
979 | this.options = options || marked.defaults;
|
980 | this.options.renderer = this.options.renderer || new Renderer();
|
981 | this.renderer = this.options.renderer;
|
982 | this.renderer.options = this.options;
|
983 | }
|
984 |
|
985 | /**
|
986 | * Static Parse Method
|
987 | */
|
988 |
|
989 | Parser.parse = function(src, options) {
|
990 | var parser = new Parser(options);
|
991 | return parser.parse(src);
|
992 | };
|
993 |
|
994 | /**
|
995 | * Parse Loop
|
996 | */
|
997 |
|
998 | Parser.prototype.parse = function(src) {
|
999 | this.inline = new InlineLexer(src.links, this.options);
|
1000 | // use an InlineLexer with a TextRenderer to extract pure text
|
1001 | this.inlineText = new InlineLexer(
|
1002 | src.links,
|
1003 | merge({}, this.options, {renderer: new TextRenderer()})
|
1004 | );
|
1005 | this.tokens = src.reverse();
|
1006 |
|
1007 | var out = '';
|
1008 | while (this.next()) {
|
1009 | out += this.tok();
|
1010 | }
|
1011 |
|
1012 | return out;
|
1013 | };
|
1014 |
|
1015 | /**
|
1016 | * Next Token
|
1017 | */
|
1018 |
|
1019 | Parser.prototype.next = function() {
|
1020 | return this.token = this.tokens.pop();
|
1021 | };
|
1022 |
|
1023 | /**
|
1024 | * Preview Next Token
|
1025 | */
|
1026 |
|
1027 | Parser.prototype.peek = function() {
|
1028 | return this.tokens[this.tokens.length - 1] || 0;
|
1029 | };
|
1030 |
|
1031 | /**
|
1032 | * Parse Text Tokens
|
1033 | */
|
1034 |
|
1035 | Parser.prototype.parseText = function() {
|
1036 | var body = this.token.text;
|
1037 |
|
1038 | while (this.peek().type === 'text') {
|
1039 | body += '\n' + this.next().text;
|
1040 | }
|
1041 |
|
1042 | return this.inline.output(body);
|
1043 | };
|
1044 |
|
1045 | /**
|
1046 | * Parse Current Token
|
1047 | */
|
1048 |
|
1049 | Parser.prototype.tok = function() {
|
1050 | switch (this.token.type) {
|
1051 | case 'space': {
|
1052 | return '';
|
1053 | }
|
1054 | case 'hr': {
|
1055 | return this.renderer.hr();
|
1056 | }
|
1057 | case 'heading': {
|
1058 | return this.renderer.heading(
|
1059 | this.inline.output(this.token.text),
|
1060 | this.token.depth,
|
1061 | unescape(this.inlineText.output(this.token.text)));
|
1062 | }
|
1063 | case 'code': {
|
1064 | return this.renderer.code(this.token.text,
|
1065 | this.token.lang,
|
1066 | this.token.escaped);
|
1067 | }
|
1068 | case 'table': {
|
1069 | var header = '',
|
1070 | body = '',
|
1071 | i,
|
1072 | row,
|
1073 | cell,
|
1074 | j;
|
1075 |
|
1076 | // header
|
1077 | cell = '';
|
1078 | for (i = 0; i < this.token.header.length; i++) {
|
1079 | cell += this.renderer.tablecell(
|
1080 | this.inline.output(this.token.header[i]),
|
1081 | { header: true, align: this.token.align[i] }
|
1082 | );
|
1083 | }
|
1084 | header += this.renderer.tablerow(cell);
|
1085 |
|
1086 | for (i = 0; i < this.token.cells.length; i++) {
|
1087 | row = this.token.cells[i];
|
1088 |
|
1089 | cell = '';
|
1090 | for (j = 0; j < row.length; j++) {
|
1091 | cell += this.renderer.tablecell(
|
1092 | this.inline.output(row[j]),
|
1093 | { header: false, align: this.token.align[j] }
|
1094 | );
|
1095 | }
|
1096 |
|
1097 | body += this.renderer.tablerow(cell);
|
1098 | }
|
1099 | return this.renderer.table(header, body);
|
1100 | }
|
1101 | case 'blockquote_start': {
|
1102 | body = '';
|
1103 |
|
1104 | while (this.next().type !== 'blockquote_end') {
|
1105 | body += this.tok();
|
1106 | }
|
1107 |
|
1108 | return this.renderer.blockquote(body);
|
1109 | }
|
1110 | case 'list_start': {
|
1111 | body = '';
|
1112 | var ordered = this.token.ordered,
|
1113 | start = this.token.start;
|
1114 |
|
1115 | while (this.next().type !== 'list_end') {
|
1116 | body += this.tok();
|
1117 | }
|
1118 |
|
1119 | return this.renderer.list(body, ordered, start);
|
1120 | }
|
1121 | case 'list_item_start': {
|
1122 | body = '';
|
1123 |
|
1124 | while (this.next().type !== 'list_item_end') {
|
1125 | body += this.token.type === 'text'
|
1126 | ? this.parseText()
|
1127 | : this.tok();
|
1128 | }
|
1129 |
|
1130 | return this.renderer.listitem(body);
|
1131 | }
|
1132 | case 'loose_item_start': {
|
1133 | body = '';
|
1134 |
|
1135 | while (this.next().type !== 'list_item_end') {
|
1136 | body += this.tok();
|
1137 | }
|
1138 |
|
1139 | return this.renderer.listitem(body);
|
1140 | }
|
1141 | case 'html': {
|
1142 | var html = !this.token.pre && !this.options.pedantic
|
1143 | ? this.inline.output(this.token.text)
|
1144 | : this.token.text;
|
1145 | return this.renderer.html(html);
|
1146 | }
|
1147 | case 'paragraph': {
|
1148 | return this.renderer.paragraph(this.inline.output(this.token.text));
|
1149 | }
|
1150 | case 'text': {
|
1151 | return this.renderer.paragraph(this.parseText());
|
1152 | }
|
1153 | }
|
1154 | };
|
1155 |
|
1156 | /**
|
1157 | * Helpers
|
1158 | */
|
1159 |
|
1160 | function escape(html, encode) {
|
1161 | return html
|
1162 | .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
|
1163 | .replace(/</g, '<')
|
1164 | .replace(/>/g, '>')
|
1165 | .replace(/"/g, '"')
|
1166 | .replace(/'/g, ''');
|
1167 | }
|
1168 |
|
1169 | function unescape(html) {
|
1170 | // explicitly match decimal, hex, and named HTML entities
|
1171 | return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) {
|
1172 | n = n.toLowerCase();
|
1173 | if (n === 'colon') return ':';
|
1174 | if (n.charAt(0) === '#') {
|
1175 | return n.charAt(1) === 'x'
|
1176 | ? String.fromCharCode(parseInt(n.substring(2), 16))
|
1177 | : String.fromCharCode(+n.substring(1));
|
1178 | }
|
1179 | return '';
|
1180 | });
|
1181 | }
|
1182 |
|
1183 | function edit(regex, opt) {
|
1184 | regex = regex.source;
|
1185 | opt = opt || '';
|
1186 | return {
|
1187 | replace: function(name, val) {
|
1188 | val = val.source || val;
|
1189 | val = val.replace(/(^|[^\[])\^/g, '$1');
|
1190 | regex = regex.replace(name, val);
|
1191 | return this;
|
1192 | },
|
1193 | getRegex: function() {
|
1194 | return new RegExp(regex, opt);
|
1195 | }
|
1196 | };
|
1197 | }
|
1198 |
|
1199 | function resolveUrl(base, href) {
|
1200 | if (!baseUrls[' ' + base]) {
|
1201 | // we can ignore everything in base after the last slash of its path component,
|
1202 | // but we might need to add _that_
|
1203 | // https://tools.ietf.org/html/rfc3986#section-3
|
1204 | if (/^[^:]+:\/*[^/]*$/.test(base)) {
|
1205 | baseUrls[' ' + base] = base + '/';
|
1206 | } else {
|
1207 | baseUrls[' ' + base] = base.replace(/[^/]*$/, '');
|
1208 | }
|
1209 | }
|
1210 | base = baseUrls[' ' + base];
|
1211 |
|
1212 | if (href.slice(0, 2) === '//') {
|
1213 | return base.replace(/:[\s\S]*/, ':') + href;
|
1214 | } else if (href.charAt(0) === '/') {
|
1215 | return base.replace(/(:\/*[^/]*)[\s\S]*/, '$1') + href;
|
1216 | } else {
|
1217 | return base + href;
|
1218 | }
|
1219 | }
|
1220 | var baseUrls = {};
|
1221 | var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
1222 |
|
1223 | function noop() {}
|
1224 | noop.exec = noop;
|
1225 |
|
1226 | function merge(obj) {
|
1227 | var i = 1,
|
1228 | target,
|
1229 | key;
|
1230 |
|
1231 | for (; i < arguments.length; i++) {
|
1232 | target = arguments[i];
|
1233 | for (key in target) {
|
1234 | if (Object.prototype.hasOwnProperty.call(target, key)) {
|
1235 | obj[key] = target[key];
|
1236 | }
|
1237 | }
|
1238 | }
|
1239 |
|
1240 | return obj;
|
1241 | }
|
1242 |
|
1243 | /**
|
1244 | * Marked
|
1245 | */
|
1246 |
|
1247 | function marked(src, opt, callback) {
|
1248 | // throw error in case of non string input
|
1249 | if (typeof src === 'undefined' || src === null) {
|
1250 | throw new Error('marked(): input parameter is undefined or null');
|
1251 | }
|
1252 | if (typeof src !== 'string') {
|
1253 | throw new Error('marked(): input parameter is of type '
|
1254 | + Object.prototype.toString.call(src) + ', string expected');
|
1255 | }
|
1256 |
|
1257 | if (callback || typeof opt === 'function') {
|
1258 | if (!callback) {
|
1259 | callback = opt;
|
1260 | opt = null;
|
1261 | }
|
1262 |
|
1263 | opt = merge({}, marked.defaults, opt || {});
|
1264 |
|
1265 | var highlight = opt.highlight,
|
1266 | tokens,
|
1267 | pending,
|
1268 | i = 0;
|
1269 |
|
1270 | try {
|
1271 | tokens = Lexer.lex(src, opt);
|
1272 | } catch (e) {
|
1273 | return callback(e);
|
1274 | }
|
1275 |
|
1276 | pending = tokens.length;
|
1277 |
|
1278 | var done = function(err) {
|
1279 | if (err) {
|
1280 | opt.highlight = highlight;
|
1281 | return callback(err);
|
1282 | }
|
1283 |
|
1284 | var out;
|
1285 |
|
1286 | try {
|
1287 | out = Parser.parse(tokens, opt);
|
1288 | } catch (e) {
|
1289 | err = e;
|
1290 | }
|
1291 |
|
1292 | opt.highlight = highlight;
|
1293 |
|
1294 | return err
|
1295 | ? callback(err)
|
1296 | : callback(null, out);
|
1297 | };
|
1298 |
|
1299 | if (!highlight || highlight.length < 3) {
|
1300 | return done();
|
1301 | }
|
1302 |
|
1303 | delete opt.highlight;
|
1304 |
|
1305 | if (!pending) return done();
|
1306 |
|
1307 | for (; i < tokens.length; i++) {
|
1308 | (function(token) {
|
1309 | if (token.type !== 'code') {
|
1310 | return --pending || done();
|
1311 | }
|
1312 | return highlight(token.text, token.lang, function(err, code) {
|
1313 | if (err) return done(err);
|
1314 | if (code == null || code === token.text) {
|
1315 | return --pending || done();
|
1316 | }
|
1317 | token.text = code;
|
1318 | token.escaped = true;
|
1319 | --pending || done();
|
1320 | });
|
1321 | })(tokens[i]);
|
1322 | }
|
1323 |
|
1324 | return;
|
1325 | }
|
1326 | try {
|
1327 | if (opt) opt = merge({}, marked.defaults, opt);
|
1328 | return Parser.parse(Lexer.lex(src, opt), opt);
|
1329 | } catch (e) {
|
1330 | e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
1331 | if ((opt || marked.defaults).silent) {
|
1332 | return '<p>An error occurred:</p><pre>'
|
1333 | + escape(e.message + '', true)
|
1334 | + '</pre>';
|
1335 | }
|
1336 | throw e;
|
1337 | }
|
1338 | }
|
1339 |
|
1340 | /**
|
1341 | * Options
|
1342 | */
|
1343 |
|
1344 | marked.options =
|
1345 | marked.setOptions = function(opt) {
|
1346 | merge(marked.defaults, opt);
|
1347 | return marked;
|
1348 | };
|
1349 |
|
1350 | marked.defaults = {
|
1351 | gfm: true,
|
1352 | tables: true,
|
1353 | breaks: false,
|
1354 | pedantic: false,
|
1355 | sanitize: false,
|
1356 | sanitizer: null,
|
1357 | mangle: true,
|
1358 | smartLists: false,
|
1359 | silent: false,
|
1360 | highlight: null,
|
1361 | langPrefix: 'lang-',
|
1362 | smartypants: false,
|
1363 | headerPrefix: '',
|
1364 | renderer: new Renderer(),
|
1365 | xhtml: false,
|
1366 | baseUrl: null
|
1367 | };
|
1368 |
|
1369 | /**
|
1370 | * Expose
|
1371 | */
|
1372 |
|
1373 | marked.Parser = Parser;
|
1374 | marked.parser = Parser.parse;
|
1375 |
|
1376 | marked.Renderer = Renderer;
|
1377 | marked.TextRenderer = TextRenderer;
|
1378 |
|
1379 | marked.Lexer = Lexer;
|
1380 | marked.lexer = Lexer.lex;
|
1381 |
|
1382 | marked.InlineLexer = InlineLexer;
|
1383 | marked.inlineLexer = InlineLexer.output;
|
1384 |
|
1385 | marked.parse = marked;
|
1386 |
|
1387 | {
|
1388 | module.exports = marked;
|
1389 | }
|
1390 | })();
|
1391 | });
|
1392 |
|
1393 | var prism = createCommonjsModule(function (module) {
|
1394 | /* **********************************************
|
1395 | Begin prism-core.js
|
1396 | ********************************************** */
|
1397 |
|
1398 | var _self = (typeof window !== 'undefined')
|
1399 | ? window // if in browser
|
1400 | : (
|
1401 | (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
|
1402 | ? self // if in worker
|
1403 | : {} // if in node js
|
1404 | );
|
1405 |
|
1406 | /**
|
1407 | * Prism: Lightweight, robust, elegant syntax highlighting
|
1408 | * MIT license http://www.opensource.org/licenses/mit-license.php/
|
1409 | * @author Lea Verou http://lea.verou.me
|
1410 | */
|
1411 |
|
1412 | var Prism = (function(){
|
1413 |
|
1414 | // Private helper vars
|
1415 | var lang = /\blang(?:uage)?-(\w+)\b/i;
|
1416 | var uniqueId = 0;
|
1417 |
|
1418 | var _ = _self.Prism = {
|
1419 | manual: _self.Prism && _self.Prism.manual,
|
1420 | disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
|
1421 | util: {
|
1422 | encode: function (tokens) {
|
1423 | if (tokens instanceof Token) {
|
1424 | return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
|
1425 | } else if (_.util.type(tokens) === 'Array') {
|
1426 | return tokens.map(_.util.encode);
|
1427 | } else {
|
1428 | return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ');
|
1429 | }
|
1430 | },
|
1431 |
|
1432 | type: function (o) {
|
1433 | return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
|
1434 | },
|
1435 |
|
1436 | objId: function (obj) {
|
1437 | if (!obj['__id']) {
|
1438 | Object.defineProperty(obj, '__id', { value: ++uniqueId });
|
1439 | }
|
1440 | return obj['__id'];
|
1441 | },
|
1442 |
|
1443 | // Deep clone a language definition (e.g. to extend it)
|
1444 | clone: function (o) {
|
1445 | var type = _.util.type(o);
|
1446 |
|
1447 | switch (type) {
|
1448 | case 'Object':
|
1449 | var clone = {};
|
1450 |
|
1451 | for (var key in o) {
|
1452 | if (o.hasOwnProperty(key)) {
|
1453 | clone[key] = _.util.clone(o[key]);
|
1454 | }
|
1455 | }
|
1456 |
|
1457 | return clone;
|
1458 |
|
1459 | case 'Array':
|
1460 | return o.map(function(v) { return _.util.clone(v); });
|
1461 | }
|
1462 |
|
1463 | return o;
|
1464 | }
|
1465 | },
|
1466 |
|
1467 | languages: {
|
1468 | extend: function (id, redef) {
|
1469 | var lang = _.util.clone(_.languages[id]);
|
1470 |
|
1471 | for (var key in redef) {
|
1472 | lang[key] = redef[key];
|
1473 | }
|
1474 |
|
1475 | return lang;
|
1476 | },
|
1477 |
|
1478 | /**
|
1479 | * Insert a token before another token in a language literal
|
1480 | * As this needs to recreate the object (we cannot actually insert before keys in object literals),
|
1481 | * we cannot just provide an object, we need anobject and a key.
|
1482 | * @param inside The key (or language id) of the parent
|
1483 | * @param before The key to insert before. If not provided, the function appends instead.
|
1484 | * @param insert Object with the key/value pairs to insert
|
1485 | * @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
|
1486 | */
|
1487 | insertBefore: function (inside, before, insert, root) {
|
1488 | root = root || _.languages;
|
1489 | var grammar = root[inside];
|
1490 |
|
1491 | if (arguments.length == 2) {
|
1492 | insert = arguments[1];
|
1493 |
|
1494 | for (var newToken in insert) {
|
1495 | if (insert.hasOwnProperty(newToken)) {
|
1496 | grammar[newToken] = insert[newToken];
|
1497 | }
|
1498 | }
|
1499 |
|
1500 | return grammar;
|
1501 | }
|
1502 |
|
1503 | var ret = {};
|
1504 |
|
1505 | for (var token in grammar) {
|
1506 |
|
1507 | if (grammar.hasOwnProperty(token)) {
|
1508 |
|
1509 | if (token == before) {
|
1510 |
|
1511 | for (var newToken in insert) {
|
1512 |
|
1513 | if (insert.hasOwnProperty(newToken)) {
|
1514 | ret[newToken] = insert[newToken];
|
1515 | }
|
1516 | }
|
1517 | }
|
1518 |
|
1519 | ret[token] = grammar[token];
|
1520 | }
|
1521 | }
|
1522 |
|
1523 | // Update references in other language definitions
|
1524 | _.languages.DFS(_.languages, function(key, value) {
|
1525 | if (value === root[inside] && key != inside) {
|
1526 | this[key] = ret;
|
1527 | }
|
1528 | });
|
1529 |
|
1530 | return root[inside] = ret;
|
1531 | },
|
1532 |
|
1533 | // Traverse a language definition with Depth First Search
|
1534 | DFS: function(o, callback, type, visited) {
|
1535 | visited = visited || {};
|
1536 | for (var i in o) {
|
1537 | if (o.hasOwnProperty(i)) {
|
1538 | callback.call(o, i, o[i], type || i);
|
1539 |
|
1540 | if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
|
1541 | visited[_.util.objId(o[i])] = true;
|
1542 | _.languages.DFS(o[i], callback, null, visited);
|
1543 | }
|
1544 | else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
|
1545 | visited[_.util.objId(o[i])] = true;
|
1546 | _.languages.DFS(o[i], callback, i, visited);
|
1547 | }
|
1548 | }
|
1549 | }
|
1550 | }
|
1551 | },
|
1552 | plugins: {},
|
1553 |
|
1554 | highlightAll: function(async, callback) {
|
1555 | _.highlightAllUnder(document, async, callback);
|
1556 | },
|
1557 |
|
1558 | highlightAllUnder: function(container, async, callback) {
|
1559 | var env = {
|
1560 | callback: callback,
|
1561 | selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
|
1562 | };
|
1563 |
|
1564 | _.hooks.run("before-highlightall", env);
|
1565 |
|
1566 | var elements = env.elements || container.querySelectorAll(env.selector);
|
1567 |
|
1568 | for (var i=0, element; element = elements[i++];) {
|
1569 | _.highlightElement(element, async === true, env.callback);
|
1570 | }
|
1571 | },
|
1572 |
|
1573 | highlightElement: function(element, async, callback) {
|
1574 | // Find language
|
1575 | var language, grammar, parent = element;
|
1576 |
|
1577 | while (parent && !lang.test(parent.className)) {
|
1578 | parent = parent.parentNode;
|
1579 | }
|
1580 |
|
1581 | if (parent) {
|
1582 | language = (parent.className.match(lang) || [,''])[1].toLowerCase();
|
1583 | grammar = _.languages[language];
|
1584 | }
|
1585 |
|
1586 | // Set language on the element, if not present
|
1587 | element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
|
1588 |
|
1589 | if (element.parentNode) {
|
1590 | // Set language on the parent, for styling
|
1591 | parent = element.parentNode;
|
1592 |
|
1593 | if (/pre/i.test(parent.nodeName)) {
|
1594 | parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
|
1595 | }
|
1596 | }
|
1597 |
|
1598 | var code = element.textContent;
|
1599 |
|
1600 | var env = {
|
1601 | element: element,
|
1602 | language: language,
|
1603 | grammar: grammar,
|
1604 | code: code
|
1605 | };
|
1606 |
|
1607 | _.hooks.run('before-sanity-check', env);
|
1608 |
|
1609 | if (!env.code || !env.grammar) {
|
1610 | if (env.code) {
|
1611 | _.hooks.run('before-highlight', env);
|
1612 | env.element.textContent = env.code;
|
1613 | _.hooks.run('after-highlight', env);
|
1614 | }
|
1615 | _.hooks.run('complete', env);
|
1616 | return;
|
1617 | }
|
1618 |
|
1619 | _.hooks.run('before-highlight', env);
|
1620 |
|
1621 | if (async && _self.Worker) {
|
1622 | var worker = new Worker(_.filename);
|
1623 |
|
1624 | worker.onmessage = function(evt) {
|
1625 | env.highlightedCode = evt.data;
|
1626 |
|
1627 | _.hooks.run('before-insert', env);
|
1628 |
|
1629 | env.element.innerHTML = env.highlightedCode;
|
1630 |
|
1631 | callback && callback.call(env.element);
|
1632 | _.hooks.run('after-highlight', env);
|
1633 | _.hooks.run('complete', env);
|
1634 | };
|
1635 |
|
1636 | worker.postMessage(JSON.stringify({
|
1637 | language: env.language,
|
1638 | code: env.code,
|
1639 | immediateClose: true
|
1640 | }));
|
1641 | }
|
1642 | else {
|
1643 | env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
|
1644 |
|
1645 | _.hooks.run('before-insert', env);
|
1646 |
|
1647 | env.element.innerHTML = env.highlightedCode;
|
1648 |
|
1649 | callback && callback.call(element);
|
1650 |
|
1651 | _.hooks.run('after-highlight', env);
|
1652 | _.hooks.run('complete', env);
|
1653 | }
|
1654 | },
|
1655 |
|
1656 | highlight: function (text, grammar, language) {
|
1657 | var tokens = _.tokenize(text, grammar);
|
1658 | return Token.stringify(_.util.encode(tokens), language);
|
1659 | },
|
1660 |
|
1661 | matchGrammar: function (text, strarr, grammar, index, startPos, oneshot, target) {
|
1662 | var Token = _.Token;
|
1663 |
|
1664 | for (var token in grammar) {
|
1665 | if(!grammar.hasOwnProperty(token) || !grammar[token]) {
|
1666 | continue;
|
1667 | }
|
1668 |
|
1669 | if (token == target) {
|
1670 | return;
|
1671 | }
|
1672 |
|
1673 | var patterns = grammar[token];
|
1674 | patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];
|
1675 |
|
1676 | for (var j = 0; j < patterns.length; ++j) {
|
1677 | var pattern = patterns[j],
|
1678 | inside = pattern.inside,
|
1679 | lookbehind = !!pattern.lookbehind,
|
1680 | greedy = !!pattern.greedy,
|
1681 | lookbehindLength = 0,
|
1682 | alias = pattern.alias;
|
1683 |
|
1684 | if (greedy && !pattern.pattern.global) {
|
1685 | // Without the global flag, lastIndex won't work
|
1686 | var flags = pattern.pattern.toString().match(/[imuy]*$/)[0];
|
1687 | pattern.pattern = RegExp(pattern.pattern.source, flags + "g");
|
1688 | }
|
1689 |
|
1690 | pattern = pattern.pattern || pattern;
|
1691 |
|
1692 | // Don’t cache length as it changes during the loop
|
1693 | for (var i = index, pos = startPos; i < strarr.length; pos += strarr[i].length, ++i) {
|
1694 |
|
1695 | var str = strarr[i];
|
1696 |
|
1697 | if (strarr.length > text.length) {
|
1698 | // Something went terribly wrong, ABORT, ABORT!
|
1699 | return;
|
1700 | }
|
1701 |
|
1702 | if (str instanceof Token) {
|
1703 | continue;
|
1704 | }
|
1705 |
|
1706 | pattern.lastIndex = 0;
|
1707 |
|
1708 | var match = pattern.exec(str),
|
1709 | delNum = 1;
|
1710 |
|
1711 | // Greedy patterns can override/remove up to two previously matched tokens
|
1712 | if (!match && greedy && i != strarr.length - 1) {
|
1713 | pattern.lastIndex = pos;
|
1714 | match = pattern.exec(text);
|
1715 | if (!match) {
|
1716 | break;
|
1717 | }
|
1718 |
|
1719 | var from = match.index + (lookbehind ? match[1].length : 0),
|
1720 | to = match.index + match[0].length,
|
1721 | k = i,
|
1722 | p = pos;
|
1723 |
|
1724 | for (var len = strarr.length; k < len && (p < to || (!strarr[k].type && !strarr[k - 1].greedy)); ++k) {
|
1725 | p += strarr[k].length;
|
1726 | // Move the index i to the element in strarr that is closest to from
|
1727 | if (from >= p) {
|
1728 | ++i;
|
1729 | pos = p;
|
1730 | }
|
1731 | }
|
1732 |
|
1733 | /*
|
1734 | * If strarr[i] is a Token, then the match starts inside another Token, which is invalid
|
1735 | * If strarr[k - 1] is greedy we are in conflict with another greedy pattern
|
1736 | */
|
1737 | if (strarr[i] instanceof Token || strarr[k - 1].greedy) {
|
1738 | continue;
|
1739 | }
|
1740 |
|
1741 | // Number of tokens to delete and replace with the new match
|
1742 | delNum = k - i;
|
1743 | str = text.slice(pos, p);
|
1744 | match.index -= pos;
|
1745 | }
|
1746 |
|
1747 | if (!match) {
|
1748 | if (oneshot) {
|
1749 | break;
|
1750 | }
|
1751 |
|
1752 | continue;
|
1753 | }
|
1754 |
|
1755 | if(lookbehind) {
|
1756 | lookbehindLength = match[1].length;
|
1757 | }
|
1758 |
|
1759 | var from = match.index + lookbehindLength,
|
1760 | match = match[0].slice(lookbehindLength),
|
1761 | to = from + match.length,
|
1762 | before = str.slice(0, from),
|
1763 | after = str.slice(to);
|
1764 |
|
1765 | var args = [i, delNum];
|
1766 |
|
1767 | if (before) {
|
1768 | ++i;
|
1769 | pos += before.length;
|
1770 | args.push(before);
|
1771 | }
|
1772 |
|
1773 | var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy);
|
1774 |
|
1775 | args.push(wrapped);
|
1776 |
|
1777 | if (after) {
|
1778 | args.push(after);
|
1779 | }
|
1780 |
|
1781 | Array.prototype.splice.apply(strarr, args);
|
1782 |
|
1783 | if (delNum != 1)
|
1784 | _.matchGrammar(text, strarr, grammar, i, pos, true, token);
|
1785 |
|
1786 | if (oneshot)
|
1787 | break;
|
1788 | }
|
1789 | }
|
1790 | }
|
1791 | },
|
1792 |
|
1793 | tokenize: function(text, grammar, language) {
|
1794 | var strarr = [text];
|
1795 |
|
1796 | var rest = grammar.rest;
|
1797 |
|
1798 | if (rest) {
|
1799 | for (var token in rest) {
|
1800 | grammar[token] = rest[token];
|
1801 | }
|
1802 |
|
1803 | delete grammar.rest;
|
1804 | }
|
1805 |
|
1806 | _.matchGrammar(text, strarr, grammar, 0, 0, false);
|
1807 |
|
1808 | return strarr;
|
1809 | },
|
1810 |
|
1811 | hooks: {
|
1812 | all: {},
|
1813 |
|
1814 | add: function (name, callback) {
|
1815 | var hooks = _.hooks.all;
|
1816 |
|
1817 | hooks[name] = hooks[name] || [];
|
1818 |
|
1819 | hooks[name].push(callback);
|
1820 | },
|
1821 |
|
1822 | run: function (name, env) {
|
1823 | var callbacks = _.hooks.all[name];
|
1824 |
|
1825 | if (!callbacks || !callbacks.length) {
|
1826 | return;
|
1827 | }
|
1828 |
|
1829 | for (var i=0, callback; callback = callbacks[i++];) {
|
1830 | callback(env);
|
1831 | }
|
1832 | }
|
1833 | }
|
1834 | };
|
1835 |
|
1836 | var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
|
1837 | this.type = type;
|
1838 | this.content = content;
|
1839 | this.alias = alias;
|
1840 | // Copy of the full string this token was created from
|
1841 | this.length = (matchedStr || "").length|0;
|
1842 | this.greedy = !!greedy;
|
1843 | };
|
1844 |
|
1845 | Token.stringify = function(o, language, parent) {
|
1846 | if (typeof o == 'string') {
|
1847 | return o;
|
1848 | }
|
1849 |
|
1850 | if (_.util.type(o) === 'Array') {
|
1851 | return o.map(function(element) {
|
1852 | return Token.stringify(element, language, o);
|
1853 | }).join('');
|
1854 | }
|
1855 |
|
1856 | var env = {
|
1857 | type: o.type,
|
1858 | content: Token.stringify(o.content, language, parent),
|
1859 | tag: 'span',
|
1860 | classes: ['token', o.type],
|
1861 | attributes: {},
|
1862 | language: language,
|
1863 | parent: parent
|
1864 | };
|
1865 |
|
1866 | if (o.alias) {
|
1867 | var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
|
1868 | Array.prototype.push.apply(env.classes, aliases);
|
1869 | }
|
1870 |
|
1871 | _.hooks.run('wrap', env);
|
1872 |
|
1873 | var attributes = Object.keys(env.attributes).map(function(name) {
|
1874 | return name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"';
|
1875 | }).join(' ');
|
1876 |
|
1877 | return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';
|
1878 |
|
1879 | };
|
1880 |
|
1881 | if (!_self.document) {
|
1882 | if (!_self.addEventListener) {
|
1883 | // in Node.js
|
1884 | return _self.Prism;
|
1885 | }
|
1886 |
|
1887 | if (!_.disableWorkerMessageHandler) {
|
1888 | // In worker
|
1889 | _self.addEventListener('message', function (evt) {
|
1890 | var message = JSON.parse(evt.data),
|
1891 | lang = message.language,
|
1892 | code = message.code,
|
1893 | immediateClose = message.immediateClose;
|
1894 |
|
1895 | _self.postMessage(_.highlight(code, _.languages[lang], lang));
|
1896 | if (immediateClose) {
|
1897 | _self.close();
|
1898 | }
|
1899 | }, false);
|
1900 | }
|
1901 |
|
1902 | return _self.Prism;
|
1903 | }
|
1904 |
|
1905 | //Get current script and highlight
|
1906 | var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop();
|
1907 |
|
1908 | if (script) {
|
1909 | _.filename = script.src;
|
1910 |
|
1911 | if (!_.manual && !script.hasAttribute('data-manual')) {
|
1912 | if(document.readyState !== "loading") {
|
1913 | if (window.requestAnimationFrame) {
|
1914 | window.requestAnimationFrame(_.highlightAll);
|
1915 | } else {
|
1916 | window.setTimeout(_.highlightAll, 16);
|
1917 | }
|
1918 | }
|
1919 | else {
|
1920 | document.addEventListener('DOMContentLoaded', _.highlightAll);
|
1921 | }
|
1922 | }
|
1923 | }
|
1924 |
|
1925 | return _self.Prism;
|
1926 |
|
1927 | })();
|
1928 |
|
1929 | if ( module.exports) {
|
1930 | module.exports = Prism;
|
1931 | }
|
1932 |
|
1933 | // hack for components to work correctly in node.js
|
1934 | if (typeof commonjsGlobal !== 'undefined') {
|
1935 | commonjsGlobal.Prism = Prism;
|
1936 | }
|
1937 |
|
1938 |
|
1939 | /* **********************************************
|
1940 | Begin prism-markup.js
|
1941 | ********************************************** */
|
1942 |
|
1943 | Prism.languages.markup = {
|
1944 | 'comment': /<!--[\s\S]*?-->/,
|
1945 | 'prolog': /<\?[\s\S]+?\?>/,
|
1946 | 'doctype': /<!DOCTYPE[\s\S]+?>/i,
|
1947 | 'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
|
1948 | 'tag': {
|
1949 | pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i,
|
1950 | inside: {
|
1951 | 'tag': {
|
1952 | pattern: /^<\/?[^\s>\/]+/i,
|
1953 | inside: {
|
1954 | 'punctuation': /^<\/?/,
|
1955 | 'namespace': /^[^\s>\/:]+:/
|
1956 | }
|
1957 | },
|
1958 | 'attr-value': {
|
1959 | pattern: /=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+)/i,
|
1960 | inside: {
|
1961 | 'punctuation': [
|
1962 | /^=/,
|
1963 | {
|
1964 | pattern: /(^|[^\\])["']/,
|
1965 | lookbehind: true
|
1966 | }
|
1967 | ]
|
1968 | }
|
1969 | },
|
1970 | 'punctuation': /\/?>/,
|
1971 | 'attr-name': {
|
1972 | pattern: /[^\s>\/]+/,
|
1973 | inside: {
|
1974 | 'namespace': /^[^\s>\/:]+:/
|
1975 | }
|
1976 | }
|
1977 |
|
1978 | }
|
1979 | },
|
1980 | 'entity': /&#?[\da-z]{1,8};/i
|
1981 | };
|
1982 |
|
1983 | Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
|
1984 | Prism.languages.markup['entity'];
|
1985 |
|
1986 | // Plugin to make entity title show the real entity, idea by Roman Komarov
|
1987 | Prism.hooks.add('wrap', function(env) {
|
1988 |
|
1989 | if (env.type === 'entity') {
|
1990 | env.attributes['title'] = env.content.replace(/&/, '&');
|
1991 | }
|
1992 | });
|
1993 |
|
1994 | Prism.languages.xml = Prism.languages.markup;
|
1995 | Prism.languages.html = Prism.languages.markup;
|
1996 | Prism.languages.mathml = Prism.languages.markup;
|
1997 | Prism.languages.svg = Prism.languages.markup;
|
1998 |
|
1999 |
|
2000 | /* **********************************************
|
2001 | Begin prism-css.js
|
2002 | ********************************************** */
|
2003 |
|
2004 | Prism.languages.css = {
|
2005 | 'comment': /\/\*[\s\S]*?\*\//,
|
2006 | 'atrule': {
|
2007 | pattern: /@[\w-]+?.*?(?:;|(?=\s*\{))/i,
|
2008 | inside: {
|
2009 | 'rule': /@[\w-]+/
|
2010 | // See rest below
|
2011 | }
|
2012 | },
|
2013 | 'url': /url\((?:(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
|
2014 | 'selector': /[^{}\s][^{};]*?(?=\s*\{)/,
|
2015 | 'string': {
|
2016 | pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
2017 | greedy: true
|
2018 | },
|
2019 | 'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,
|
2020 | 'important': /\B!important\b/i,
|
2021 | 'function': /[-a-z0-9]+(?=\()/i,
|
2022 | 'punctuation': /[(){};:]/
|
2023 | };
|
2024 |
|
2025 | Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css);
|
2026 |
|
2027 | if (Prism.languages.markup) {
|
2028 | Prism.languages.insertBefore('markup', 'tag', {
|
2029 | 'style': {
|
2030 | pattern: /(<style[\s\S]*?>)[\s\S]*?(?=<\/style>)/i,
|
2031 | lookbehind: true,
|
2032 | inside: Prism.languages.css,
|
2033 | alias: 'language-css',
|
2034 | greedy: true
|
2035 | }
|
2036 | });
|
2037 |
|
2038 | Prism.languages.insertBefore('inside', 'attr-value', {
|
2039 | 'style-attr': {
|
2040 | pattern: /\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,
|
2041 | inside: {
|
2042 | 'attr-name': {
|
2043 | pattern: /^\s*style/i,
|
2044 | inside: Prism.languages.markup.tag.inside
|
2045 | },
|
2046 | 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
|
2047 | 'attr-value': {
|
2048 | pattern: /.+/i,
|
2049 | inside: Prism.languages.css
|
2050 | }
|
2051 | },
|
2052 | alias: 'language-css'
|
2053 | }
|
2054 | }, Prism.languages.markup.tag);
|
2055 | }
|
2056 |
|
2057 | /* **********************************************
|
2058 | Begin prism-clike.js
|
2059 | ********************************************** */
|
2060 |
|
2061 | Prism.languages.clike = {
|
2062 | 'comment': [
|
2063 | {
|
2064 | pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
|
2065 | lookbehind: true
|
2066 | },
|
2067 | {
|
2068 | pattern: /(^|[^\\:])\/\/.*/,
|
2069 | lookbehind: true
|
2070 | }
|
2071 | ],
|
2072 | 'string': {
|
2073 | pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
2074 | greedy: true
|
2075 | },
|
2076 | 'class-name': {
|
2077 | pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[\w.\\]+/i,
|
2078 | lookbehind: true,
|
2079 | inside: {
|
2080 | punctuation: /[.\\]/
|
2081 | }
|
2082 | },
|
2083 | 'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
|
2084 | 'boolean': /\b(?:true|false)\b/,
|
2085 | 'function': /[a-z0-9_]+(?=\()/i,
|
2086 | 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
|
2087 | 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
|
2088 | 'punctuation': /[{}[\];(),.:]/
|
2089 | };
|
2090 |
|
2091 |
|
2092 | /* **********************************************
|
2093 | Begin prism-javascript.js
|
2094 | ********************************************** */
|
2095 |
|
2096 | Prism.languages.javascript = Prism.languages.extend('clike', {
|
2097 | 'keyword': /\b(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/,
|
2098 | 'number': /\b-?(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+|\d*\.?\d+(?:[Ee][+-]?\d+)?|NaN|Infinity)\b/,
|
2099 | // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
|
2100 | 'function': /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*\()/i,
|
2101 | 'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/
|
2102 | });
|
2103 |
|
2104 | Prism.languages.insertBefore('javascript', 'keyword', {
|
2105 | 'regex': {
|
2106 | pattern: /(^|[^/])\/(?!\/)(\[[^\]\r\n]+]|\\.|[^/\\\[\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
|
2107 | lookbehind: true,
|
2108 | greedy: true
|
2109 | },
|
2110 | // This must be declared before keyword because we use "function" inside the look-forward
|
2111 | 'function-variable': {
|
2112 | pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i,
|
2113 | alias: 'function'
|
2114 | }
|
2115 | });
|
2116 |
|
2117 | Prism.languages.insertBefore('javascript', 'string', {
|
2118 | 'template-string': {
|
2119 | pattern: /`(?:\\[\s\S]|[^\\`])*`/,
|
2120 | greedy: true,
|
2121 | inside: {
|
2122 | 'interpolation': {
|
2123 | pattern: /\$\{[^}]+\}/,
|
2124 | inside: {
|
2125 | 'interpolation-punctuation': {
|
2126 | pattern: /^\$\{|\}$/,
|
2127 | alias: 'punctuation'
|
2128 | },
|
2129 | rest: Prism.languages.javascript
|
2130 | }
|
2131 | },
|
2132 | 'string': /[\s\S]+/
|
2133 | }
|
2134 | }
|
2135 | });
|
2136 |
|
2137 | if (Prism.languages.markup) {
|
2138 | Prism.languages.insertBefore('markup', 'tag', {
|
2139 | 'script': {
|
2140 | pattern: /(<script[\s\S]*?>)[\s\S]*?(?=<\/script>)/i,
|
2141 | lookbehind: true,
|
2142 | inside: Prism.languages.javascript,
|
2143 | alias: 'language-javascript',
|
2144 | greedy: true
|
2145 | }
|
2146 | });
|
2147 | }
|
2148 |
|
2149 | Prism.languages.js = Prism.languages.javascript;
|
2150 |
|
2151 |
|
2152 | /* **********************************************
|
2153 | Begin prism-file-highlight.js
|
2154 | ********************************************** */
|
2155 |
|
2156 | (function () {
|
2157 | if (typeof self === 'undefined' || !self.Prism || !self.document || !document.querySelector) {
|
2158 | return;
|
2159 | }
|
2160 |
|
2161 | self.Prism.fileHighlight = function() {
|
2162 |
|
2163 | var Extensions = {
|
2164 | 'js': 'javascript',
|
2165 | 'py': 'python',
|
2166 | 'rb': 'ruby',
|
2167 | 'ps1': 'powershell',
|
2168 | 'psm1': 'powershell',
|
2169 | 'sh': 'bash',
|
2170 | 'bat': 'batch',
|
2171 | 'h': 'c',
|
2172 | 'tex': 'latex'
|
2173 | };
|
2174 |
|
2175 | Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function (pre) {
|
2176 | var src = pre.getAttribute('data-src');
|
2177 |
|
2178 | var language, parent = pre;
|
2179 | var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
|
2180 | while (parent && !lang.test(parent.className)) {
|
2181 | parent = parent.parentNode;
|
2182 | }
|
2183 |
|
2184 | if (parent) {
|
2185 | language = (pre.className.match(lang) || [, ''])[1];
|
2186 | }
|
2187 |
|
2188 | if (!language) {
|
2189 | var extension = (src.match(/\.(\w+)$/) || [, ''])[1];
|
2190 | language = Extensions[extension] || extension;
|
2191 | }
|
2192 |
|
2193 | var code = document.createElement('code');
|
2194 | code.className = 'language-' + language;
|
2195 |
|
2196 | pre.textContent = '';
|
2197 |
|
2198 | code.textContent = 'Loading…';
|
2199 |
|
2200 | pre.appendChild(code);
|
2201 |
|
2202 | var xhr = new XMLHttpRequest();
|
2203 |
|
2204 | xhr.open('GET', src, true);
|
2205 |
|
2206 | xhr.onreadystatechange = function () {
|
2207 | if (xhr.readyState == 4) {
|
2208 |
|
2209 | if (xhr.status < 400 && xhr.responseText) {
|
2210 | code.textContent = xhr.responseText;
|
2211 |
|
2212 | Prism.highlightElement(code);
|
2213 | }
|
2214 | else if (xhr.status >= 400) {
|
2215 | code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText;
|
2216 | }
|
2217 | else {
|
2218 | code.textContent = '✖ Error: File does not exist or is empty';
|
2219 | }
|
2220 | }
|
2221 | };
|
2222 |
|
2223 | xhr.send(null);
|
2224 | });
|
2225 |
|
2226 | };
|
2227 |
|
2228 | document.addEventListener('DOMContentLoaded', self.Prism.fileHighlight);
|
2229 |
|
2230 | })();
|
2231 | });
|
2232 |
|
2233 | (function(Prism) {
|
2234 | Prism.languages.sass = Prism.languages.extend('css', {
|
2235 | // Sass comments don't need to be closed, only indented
|
2236 | 'comment': {
|
2237 | pattern: /^([ \t]*)\/[\/*].*(?:(?:\r?\n|\r)\1[ \t]+.+)*/m,
|
2238 | lookbehind: true
|
2239 | }
|
2240 | });
|
2241 |
|
2242 | Prism.languages.insertBefore('sass', 'atrule', {
|
2243 | // We want to consume the whole line
|
2244 | 'atrule-line': {
|
2245 | // Includes support for = and + shortcuts
|
2246 | pattern: /^(?:[ \t]*)[@+=].+/m,
|
2247 | inside: {
|
2248 | 'atrule': /(?:@[\w-]+|[+=])/m
|
2249 | }
|
2250 | }
|
2251 | });
|
2252 | delete Prism.languages.sass.atrule;
|
2253 |
|
2254 |
|
2255 | var variable = /\$[-\w]+|#\{\$[-\w]+\}/;
|
2256 | var operator = [
|
2257 | /[+*\/%]|[=!]=|<=?|>=?|\b(?:and|or|not)\b/,
|
2258 | {
|
2259 | pattern: /(\s+)-(?=\s)/,
|
2260 | lookbehind: true
|
2261 | }
|
2262 | ];
|
2263 |
|
2264 | Prism.languages.insertBefore('sass', 'property', {
|
2265 | // We want to consume the whole line
|
2266 | 'variable-line': {
|
2267 | pattern: /^[ \t]*\$.+/m,
|
2268 | inside: {
|
2269 | 'punctuation': /:/,
|
2270 | 'variable': variable,
|
2271 | 'operator': operator
|
2272 | }
|
2273 | },
|
2274 | // We want to consume the whole line
|
2275 | 'property-line': {
|
2276 | pattern: /^[ \t]*(?:[^:\s]+ *:.*|:[^:\s]+.*)/m,
|
2277 | inside: {
|
2278 | 'property': [
|
2279 | /[^:\s]+(?=\s*:)/,
|
2280 | {
|
2281 | pattern: /(:)[^:\s]+/,
|
2282 | lookbehind: true
|
2283 | }
|
2284 | ],
|
2285 | 'punctuation': /:/,
|
2286 | 'variable': variable,
|
2287 | 'operator': operator,
|
2288 | 'important': Prism.languages.sass.important
|
2289 | }
|
2290 | }
|
2291 | });
|
2292 | delete Prism.languages.sass.property;
|
2293 | delete Prism.languages.sass.important;
|
2294 |
|
2295 | // Now that whole lines for other patterns are consumed,
|
2296 | // what's left should be selectors
|
2297 | delete Prism.languages.sass.selector;
|
2298 | Prism.languages.insertBefore('sass', 'punctuation', {
|
2299 | 'selector': {
|
2300 | pattern: /([ \t]*)\S(?:,?[^,\r\n]+)*(?:,(?:\r?\n|\r)\1[ \t]+\S(?:,?[^,\r\n]+)*)*/,
|
2301 | lookbehind: true
|
2302 | }
|
2303 | });
|
2304 |
|
2305 | }(Prism));
|
2306 |
|
2307 | Prism.languages.typescript = Prism.languages.extend('javascript', {
|
2308 | // From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
|
2309 | 'keyword': /\b(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield|false|true|module|declare|constructor|string|Function|any|number|boolean|Array|symbol|namespace|abstract|require|type)\b/
|
2310 | });
|
2311 |
|
2312 | Prism.languages.ts = Prism.languages.typescript;
|
2313 |
|
2314 | const Markdown = class {
|
2315 | constructor(hostRef) {
|
2316 | core.registerInstance(this, hostRef);
|
2317 | }
|
2318 | componentDidRender() {
|
2319 | this.renderMarkup();
|
2320 | }
|
2321 | renderMarkup() {
|
2322 | this.element.innerHTML = marked(this.precompile(this.data));
|
2323 | prism.highlightAll(false);
|
2324 | }
|
2325 | precompile(markdown) {
|
2326 | if (!markdown) {
|
2327 | return '';
|
2328 | }
|
2329 | let indentStart;
|
2330 | return markdown
|
2331 | .replace(/\>/g, '>')
|
2332 | .split('\n')
|
2333 | .map(line => {
|
2334 | // find position of 1st non-whitespace character
|
2335 | // to determine the markdown indentation start
|
2336 | if (line.length > 0 && isNaN(indentStart)) {
|
2337 | indentStart = line.search(/\S|$/);
|
2338 | }
|
2339 | // remove whitespaces before indentation start
|
2340 | return indentStart ? line.substring(indentStart) : line;
|
2341 | }).join('\n');
|
2342 | }
|
2343 | get element() { return core.getElement(this); }
|
2344 | static get style() { return "ad-markdown{display:block}ad-markdown code[class*=language-],ad-markdown pre[class*=language-]{border-radius:.25rem;color:var(--anj-primary);background:none;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-ms-hyphens:none;hyphens:none}ad-markdown pre[class*=language-]{padding:1rem;margin:2rem 0;overflow:auto}ad-markdown :not(pre)>code[class*=language-],ad-markdown pre[class*=language-]{background:var(--anj-background);border:1px dashed var(--anj-border)}ad-markdown :not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}ad-markdown .token.inserted,ad-markdown .token.punctuation{color:var(--anj-secondary-dark)}ad-markdown .token.attr-value,ad-markdown .token.string{color:var(--anj-dark)}ad-markdown .token.attr-name,ad-markdown .token.char,ad-markdown .token.class-name,ad-markdown .token.constant,ad-markdown .token.function,ad-markdown .token.function-name,ad-markdown .token.property,ad-markdown .token.regex,ad-markdown .token.symbol,ad-markdown .token.variable{color:var(--anj-primary)}ad-markdown .token.atrule,ad-markdown .token.boolean,ad-markdown .token.builtin,ad-markdown .token.deleted,ad-markdown .token.important,ad-markdown .token.keyword,ad-markdown .token.namespace,ad-markdown .token.number,ad-markdown .token.selector,ad-markdown .token.tag{color:var(--anj-highlight-dark)}ad-markdown .token.block-comment,ad-markdown .token.cdata,ad-markdown .token.comment,ad-markdown .token.doctype,ad-markdown .token.entity,ad-markdown .token.operator,ad-markdown .token.prolog,ad-markdown .token.url{color:var(--anj-neutral)}ad-markdown .token.bold,ad-markdown .token.important{font-weight:700}ad-markdown .token.italic{font-style:italic}ad-markdown .token.entity{cursor:help}ad-markdown blockquote{padding:0 1em;color:var(--anj-primary);border-left:.25em solid var(--anj-neutral)}ad-markdown h1{font-size:2rem;font-weight:600;letter-spacing:var(--anj-spacing-wide);margin:0 0 1rem;padding:0}ad-markdown h2{font-size:1.5rem}ad-markdown h2,ad-markdown h3{font-weight:400;margin:1rem 0;padding:0}ad-markdown h3{font-size:1.25rem}ad-markdown h4{font-size:1rem}ad-markdown h4,ad-markdown h5{font-weight:400;margin:1rem 0;padding:0}ad-markdown h5{font-size:.875rem}"; }
|
2345 | };
|
2346 |
|
2347 | exports.ad_markdown = Markdown;
|