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