UNPKG

68.3 kBJavaScriptView Raw
1/**
2 * marked - a markdown parser
3 * Copyright (c) 2011-2020, Christopher Jeffrey. (MIT Licensed)
4 * https://github.com/markedjs/marked
5 */
6
7/**
8 * DO NOT EDIT THIS FILE
9 * The code in this file is generated from files in ./src/
10 */
11
12(function (global, factory) {
13 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
14 typeof define === 'function' && define.amd ? define(factory) :
15 (global = global || self, global.marked = factory());
16}(this, (function () { 'use strict';
17
18 function _defineProperties(target, props) {
19 for (var i = 0; i < props.length; i++) {
20 var descriptor = props[i];
21 descriptor.enumerable = descriptor.enumerable || false;
22 descriptor.configurable = true;
23 if ("value" in descriptor) descriptor.writable = true;
24 Object.defineProperty(target, descriptor.key, descriptor);
25 }
26 }
27
28 function _createClass(Constructor, protoProps, staticProps) {
29 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
30 if (staticProps) _defineProperties(Constructor, staticProps);
31 return Constructor;
32 }
33
34 function _unsupportedIterableToArray(o, minLen) {
35 if (!o) return;
36 if (typeof o === "string") return _arrayLikeToArray(o, minLen);
37 var n = Object.prototype.toString.call(o).slice(8, -1);
38 if (n === "Object" && o.constructor) n = o.constructor.name;
39 if (n === "Map" || n === "Set") return Array.from(o);
40 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
41 }
42
43 function _arrayLikeToArray(arr, len) {
44 if (len == null || len > arr.length) len = arr.length;
45
46 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
47
48 return arr2;
49 }
50
51 function _createForOfIteratorHelperLoose(o) {
52 var i = 0;
53
54 if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
55 if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) return function () {
56 if (i >= o.length) return {
57 done: true
58 };
59 return {
60 done: false,
61 value: o[i++]
62 };
63 };
64 throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
65 }
66
67 i = o[Symbol.iterator]();
68 return i.next.bind(i);
69 }
70
71 function createCommonjsModule(fn, module) {
72 return module = { exports: {} }, fn(module, module.exports), module.exports;
73 }
74
75 var defaults = createCommonjsModule(function (module) {
76 function getDefaults() {
77 return {
78 baseUrl: null,
79 breaks: false,
80 gfm: true,
81 headerIds: true,
82 headerPrefix: '',
83 highlight: null,
84 langPrefix: 'language-',
85 mangle: true,
86 pedantic: false,
87 renderer: null,
88 sanitize: false,
89 sanitizer: null,
90 silent: false,
91 smartLists: false,
92 smartypants: false,
93 tokenizer: null,
94 walkTokens: null,
95 xhtml: false
96 };
97 }
98
99 function changeDefaults(newDefaults) {
100 module.exports.defaults = newDefaults;
101 }
102
103 module.exports = {
104 defaults: getDefaults(),
105 getDefaults: getDefaults,
106 changeDefaults: changeDefaults
107 };
108 });
109 var defaults_1 = defaults.defaults;
110 var defaults_2 = defaults.getDefaults;
111 var defaults_3 = defaults.changeDefaults;
112
113 /**
114 * Helpers
115 */
116 var escapeTest = /[&<>"']/;
117 var escapeReplace = /[&<>"']/g;
118 var escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
119 var escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
120 var escapeReplacements = {
121 '&': '&amp;',
122 '<': '&lt;',
123 '>': '&gt;',
124 '"': '&quot;',
125 "'": '&#39;'
126 };
127
128 var getEscapeReplacement = function getEscapeReplacement(ch) {
129 return escapeReplacements[ch];
130 };
131
132 function escape(html, encode) {
133 if (encode) {
134 if (escapeTest.test(html)) {
135 return html.replace(escapeReplace, getEscapeReplacement);
136 }
137 } else {
138 if (escapeTestNoEncode.test(html)) {
139 return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
140 }
141 }
142
143 return html;
144 }
145
146 var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
147
148 function unescape(html) {
149 // explicitly match decimal, hex, and named HTML entities
150 return html.replace(unescapeTest, function (_, n) {
151 n = n.toLowerCase();
152 if (n === 'colon') return ':';
153
154 if (n.charAt(0) === '#') {
155 return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
156 }
157
158 return '';
159 });
160 }
161
162 var caret = /(^|[^\[])\^/g;
163
164 function edit(regex, opt) {
165 regex = regex.source || regex;
166 opt = opt || '';
167 var obj = {
168 replace: function replace(name, val) {
169 val = val.source || val;
170 val = val.replace(caret, '$1');
171 regex = regex.replace(name, val);
172 return obj;
173 },
174 getRegex: function getRegex() {
175 return new RegExp(regex, opt);
176 }
177 };
178 return obj;
179 }
180
181 var nonWordAndColonTest = /[^\w:]/g;
182 var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
183
184 function cleanUrl(sanitize, base, href) {
185 if (sanitize) {
186 var prot;
187
188 try {
189 prot = decodeURIComponent(unescape(href)).replace(nonWordAndColonTest, '').toLowerCase();
190 } catch (e) {
191 return null;
192 }
193
194 if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
195 return null;
196 }
197 }
198
199 if (base && !originIndependentUrl.test(href)) {
200 href = resolveUrl(base, href);
201 }
202
203 try {
204 href = encodeURI(href).replace(/%25/g, '%');
205 } catch (e) {
206 return null;
207 }
208
209 return href;
210 }
211
212 var baseUrls = {};
213 var justDomain = /^[^:]+:\/*[^/]*$/;
214 var protocol = /^([^:]+:)[\s\S]*$/;
215 var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
216
217 function resolveUrl(base, href) {
218 if (!baseUrls[' ' + base]) {
219 // we can ignore everything in base after the last slash of its path component,
220 // but we might need to add _that_
221 // https://tools.ietf.org/html/rfc3986#section-3
222 if (justDomain.test(base)) {
223 baseUrls[' ' + base] = base + '/';
224 } else {
225 baseUrls[' ' + base] = rtrim(base, '/', true);
226 }
227 }
228
229 base = baseUrls[' ' + base];
230 var relativeBase = base.indexOf(':') === -1;
231
232 if (href.substring(0, 2) === '//') {
233 if (relativeBase) {
234 return href;
235 }
236
237 return base.replace(protocol, '$1') + href;
238 } else if (href.charAt(0) === '/') {
239 if (relativeBase) {
240 return href;
241 }
242
243 return base.replace(domain, '$1') + href;
244 } else {
245 return base + href;
246 }
247 }
248
249 var noopTest = {
250 exec: function noopTest() {}
251 };
252
253 function merge(obj) {
254 var i = 1,
255 target,
256 key;
257
258 for (; i < arguments.length; i++) {
259 target = arguments[i];
260
261 for (key in target) {
262 if (Object.prototype.hasOwnProperty.call(target, key)) {
263 obj[key] = target[key];
264 }
265 }
266 }
267
268 return obj;
269 }
270
271 function splitCells(tableRow, count) {
272 // ensure that every cell-delimiting pipe has a space
273 // before it to distinguish it from an escaped pipe
274 var row = tableRow.replace(/\|/g, function (match, offset, str) {
275 var escaped = false,
276 curr = offset;
277
278 while (--curr >= 0 && str[curr] === '\\') {
279 escaped = !escaped;
280 }
281
282 if (escaped) {
283 // odd number of slashes means | is escaped
284 // so we leave it alone
285 return '|';
286 } else {
287 // add space before unescaped |
288 return ' |';
289 }
290 }),
291 cells = row.split(/ \|/);
292 var i = 0;
293
294 if (cells.length > count) {
295 cells.splice(count);
296 } else {
297 while (cells.length < count) {
298 cells.push('');
299 }
300 }
301
302 for (; i < cells.length; i++) {
303 // leading or trailing whitespace is ignored per the gfm spec
304 cells[i] = cells[i].trim().replace(/\\\|/g, '|');
305 }
306
307 return cells;
308 } // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
309 // /c*$/ is vulnerable to REDOS.
310 // invert: Remove suffix of non-c chars instead. Default falsey.
311
312
313 function rtrim(str, c, invert) {
314 var l = str.length;
315
316 if (l === 0) {
317 return '';
318 } // Length of suffix matching the invert condition.
319
320
321 var suffLen = 0; // Step left until we fail to match the invert condition.
322
323 while (suffLen < l) {
324 var currChar = str.charAt(l - suffLen - 1);
325
326 if (currChar === c && !invert) {
327 suffLen++;
328 } else if (currChar !== c && invert) {
329 suffLen++;
330 } else {
331 break;
332 }
333 }
334
335 return str.substr(0, l - suffLen);
336 }
337
338 function findClosingBracket(str, b) {
339 if (str.indexOf(b[1]) === -1) {
340 return -1;
341 }
342
343 var l = str.length;
344 var level = 0,
345 i = 0;
346
347 for (; i < l; i++) {
348 if (str[i] === '\\') {
349 i++;
350 } else if (str[i] === b[0]) {
351 level++;
352 } else if (str[i] === b[1]) {
353 level--;
354
355 if (level < 0) {
356 return i;
357 }
358 }
359 }
360
361 return -1;
362 }
363
364 function checkSanitizeDeprecation(opt) {
365 if (opt && opt.sanitize && !opt.silent) {
366 console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options');
367 }
368 }
369
370 var helpers = {
371 escape: escape,
372 unescape: unescape,
373 edit: edit,
374 cleanUrl: cleanUrl,
375 resolveUrl: resolveUrl,
376 noopTest: noopTest,
377 merge: merge,
378 splitCells: splitCells,
379 rtrim: rtrim,
380 findClosingBracket: findClosingBracket,
381 checkSanitizeDeprecation: checkSanitizeDeprecation
382 };
383
384 var defaults$1 = defaults.defaults;
385 var rtrim$1 = helpers.rtrim,
386 splitCells$1 = helpers.splitCells,
387 _escape = helpers.escape,
388 findClosingBracket$1 = helpers.findClosingBracket;
389
390 function outputLink(cap, link, raw) {
391 var href = link.href;
392 var title = link.title ? _escape(link.title) : null;
393
394 if (cap[0].charAt(0) !== '!') {
395 return {
396 type: 'link',
397 raw: raw,
398 href: href,
399 title: title,
400 text: cap[1]
401 };
402 } else {
403 return {
404 type: 'image',
405 raw: raw,
406 text: _escape(cap[1]),
407 href: href,
408 title: title
409 };
410 }
411 }
412
413 function indentCodeCompensation(raw, text) {
414 var matchIndentToCode = raw.match(/^(\s+)(?:```)/);
415
416 if (matchIndentToCode === null) {
417 return text;
418 }
419
420 var indentToCode = matchIndentToCode[1];
421 return text.split('\n').map(function (node) {
422 var matchIndentInNode = node.match(/^\s+/);
423
424 if (matchIndentInNode === null) {
425 return node;
426 }
427
428 var indentInNode = matchIndentInNode[0];
429
430 if (indentInNode.length >= indentToCode.length) {
431 return node.slice(indentToCode.length);
432 }
433
434 return node;
435 }).join('\n');
436 }
437 /**
438 * Tokenizer
439 */
440
441
442 var Tokenizer_1 = /*#__PURE__*/function () {
443 function Tokenizer(options) {
444 this.options = options || defaults$1;
445 }
446
447 var _proto = Tokenizer.prototype;
448
449 _proto.space = function space(src) {
450 var cap = this.rules.block.newline.exec(src);
451
452 if (cap) {
453 if (cap[0].length > 1) {
454 return {
455 type: 'space',
456 raw: cap[0]
457 };
458 }
459
460 return {
461 raw: '\n'
462 };
463 }
464 };
465
466 _proto.code = function code(src, tokens) {
467 var cap = this.rules.block.code.exec(src);
468
469 if (cap) {
470 var lastToken = tokens[tokens.length - 1]; // An indented code block cannot interrupt a paragraph.
471
472 if (lastToken && lastToken.type === 'paragraph') {
473 return {
474 raw: cap[0],
475 text: cap[0].trimRight()
476 };
477 }
478
479 var text = cap[0].replace(/^ {4}/gm, '');
480 return {
481 type: 'code',
482 raw: cap[0],
483 codeBlockStyle: 'indented',
484 text: !this.options.pedantic ? rtrim$1(text, '\n') : text
485 };
486 }
487 };
488
489 _proto.fences = function fences(src) {
490 var cap = this.rules.block.fences.exec(src);
491
492 if (cap) {
493 var raw = cap[0];
494 var text = indentCodeCompensation(raw, cap[3] || '');
495 return {
496 type: 'code',
497 raw: raw,
498 lang: cap[2] ? cap[2].trim() : cap[2],
499 text: text
500 };
501 }
502 };
503
504 _proto.heading = function heading(src) {
505 var cap = this.rules.block.heading.exec(src);
506
507 if (cap) {
508 return {
509 type: 'heading',
510 raw: cap[0],
511 depth: cap[1].length,
512 text: cap[2]
513 };
514 }
515 };
516
517 _proto.nptable = function nptable(src) {
518 var cap = this.rules.block.nptable.exec(src);
519
520 if (cap) {
521 var item = {
522 type: 'table',
523 header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
524 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
525 cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [],
526 raw: cap[0]
527 };
528
529 if (item.header.length === item.align.length) {
530 var l = item.align.length;
531 var i;
532
533 for (i = 0; i < l; i++) {
534 if (/^ *-+: *$/.test(item.align[i])) {
535 item.align[i] = 'right';
536 } else if (/^ *:-+: *$/.test(item.align[i])) {
537 item.align[i] = 'center';
538 } else if (/^ *:-+ *$/.test(item.align[i])) {
539 item.align[i] = 'left';
540 } else {
541 item.align[i] = null;
542 }
543 }
544
545 l = item.cells.length;
546
547 for (i = 0; i < l; i++) {
548 item.cells[i] = splitCells$1(item.cells[i], item.header.length);
549 }
550
551 return item;
552 }
553 }
554 };
555
556 _proto.hr = function hr(src) {
557 var cap = this.rules.block.hr.exec(src);
558
559 if (cap) {
560 return {
561 type: 'hr',
562 raw: cap[0]
563 };
564 }
565 };
566
567 _proto.blockquote = function blockquote(src) {
568 var cap = this.rules.block.blockquote.exec(src);
569
570 if (cap) {
571 var text = cap[0].replace(/^ *> ?/gm, '');
572 return {
573 type: 'blockquote',
574 raw: cap[0],
575 text: text
576 };
577 }
578 };
579
580 _proto.list = function list(src) {
581 var cap = this.rules.block.list.exec(src);
582
583 if (cap) {
584 var raw = cap[0];
585 var bull = cap[2];
586 var isordered = bull.length > 1;
587 var list = {
588 type: 'list',
589 raw: raw,
590 ordered: isordered,
591 start: isordered ? +bull : '',
592 loose: false,
593 items: []
594 }; // Get each top-level item.
595
596 var itemMatch = cap[0].match(this.rules.block.item);
597 var next = false,
598 item,
599 space,
600 b,
601 addBack,
602 loose,
603 istask,
604 ischecked;
605 var l = itemMatch.length;
606
607 for (var i = 0; i < l; i++) {
608 item = itemMatch[i];
609 raw = item; // Remove the list item's bullet
610 // so it is seen as the next token.
611
612 space = item.length;
613 item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the
614 // list item contains. Hacky.
615
616 if (~item.indexOf('\n ')) {
617 space -= item.length;
618 item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, '');
619 } // Determine whether the next list item belongs here.
620 // Backpedal if it does not belong in this list.
621
622
623 if (i !== l - 1) {
624 b = this.rules.block.bullet.exec(itemMatch[i + 1])[0];
625
626 if (bull.length > 1 ? b.length === 1 : b.length > 1 || this.options.smartLists && b !== bull) {
627 addBack = itemMatch.slice(i + 1).join('\n');
628 list.raw = list.raw.substring(0, list.raw.length - addBack.length);
629 i = l - 1;
630 }
631 } // Determine whether item is loose or not.
632 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
633 // for discount behavior.
634
635
636 loose = next || /\n\n(?!\s*$)/.test(item);
637
638 if (i !== l - 1) {
639 next = item.charAt(item.length - 1) === '\n';
640 if (!loose) loose = next;
641 }
642
643 if (loose) {
644 list.loose = true;
645 } // Check for task list items
646
647
648 istask = /^\[[ xX]\] /.test(item);
649 ischecked = undefined;
650
651 if (istask) {
652 ischecked = item[1] !== ' ';
653 item = item.replace(/^\[[ xX]\] +/, '');
654 }
655
656 list.items.push({
657 type: 'list_item',
658 raw: raw,
659 task: istask,
660 checked: ischecked,
661 loose: loose,
662 text: item
663 });
664 }
665
666 return list;
667 }
668 };
669
670 _proto.html = function html(src) {
671 var cap = this.rules.block.html.exec(src);
672
673 if (cap) {
674 return {
675 type: this.options.sanitize ? 'paragraph' : 'html',
676 raw: cap[0],
677 pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
678 text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
679 };
680 }
681 };
682
683 _proto.def = function def(src) {
684 var cap = this.rules.block.def.exec(src);
685
686 if (cap) {
687 if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
688 var tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
689 return {
690 tag: tag,
691 raw: cap[0],
692 href: cap[2],
693 title: cap[3]
694 };
695 }
696 };
697
698 _proto.table = function table(src) {
699 var cap = this.rules.block.table.exec(src);
700
701 if (cap) {
702 var item = {
703 type: 'table',
704 header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
705 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
706 cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
707 };
708
709 if (item.header.length === item.align.length) {
710 item.raw = cap[0];
711 var l = item.align.length;
712 var i;
713
714 for (i = 0; i < l; i++) {
715 if (/^ *-+: *$/.test(item.align[i])) {
716 item.align[i] = 'right';
717 } else if (/^ *:-+: *$/.test(item.align[i])) {
718 item.align[i] = 'center';
719 } else if (/^ *:-+ *$/.test(item.align[i])) {
720 item.align[i] = 'left';
721 } else {
722 item.align[i] = null;
723 }
724 }
725
726 l = item.cells.length;
727
728 for (i = 0; i < l; i++) {
729 item.cells[i] = splitCells$1(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length);
730 }
731
732 return item;
733 }
734 }
735 };
736
737 _proto.lheading = function lheading(src) {
738 var cap = this.rules.block.lheading.exec(src);
739
740 if (cap) {
741 return {
742 type: 'heading',
743 raw: cap[0],
744 depth: cap[2].charAt(0) === '=' ? 1 : 2,
745 text: cap[1]
746 };
747 }
748 };
749
750 _proto.paragraph = function paragraph(src) {
751 var cap = this.rules.block.paragraph.exec(src);
752
753 if (cap) {
754 return {
755 type: 'paragraph',
756 raw: cap[0],
757 text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1]
758 };
759 }
760 };
761
762 _proto.text = function text(src, tokens) {
763 var cap = this.rules.block.text.exec(src);
764
765 if (cap) {
766 var lastToken = tokens[tokens.length - 1];
767
768 if (lastToken && lastToken.type === 'text') {
769 return {
770 raw: cap[0],
771 text: cap[0]
772 };
773 }
774
775 return {
776 type: 'text',
777 raw: cap[0],
778 text: cap[0]
779 };
780 }
781 };
782
783 _proto.escape = function escape(src) {
784 var cap = this.rules.inline.escape.exec(src);
785
786 if (cap) {
787 return {
788 type: 'escape',
789 raw: cap[0],
790 text: _escape(cap[1])
791 };
792 }
793 };
794
795 _proto.tag = function tag(src, inLink, inRawBlock) {
796 var cap = this.rules.inline.tag.exec(src);
797
798 if (cap) {
799 if (!inLink && /^<a /i.test(cap[0])) {
800 inLink = true;
801 } else if (inLink && /^<\/a>/i.test(cap[0])) {
802 inLink = false;
803 }
804
805 if (!inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
806 inRawBlock = true;
807 } else if (inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
808 inRawBlock = false;
809 }
810
811 return {
812 type: this.options.sanitize ? 'text' : 'html',
813 raw: cap[0],
814 inLink: inLink,
815 inRawBlock: inRawBlock,
816 text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
817 };
818 }
819 };
820
821 _proto.link = function link(src) {
822 var cap = this.rules.inline.link.exec(src);
823
824 if (cap) {
825 var lastParenIndex = findClosingBracket$1(cap[2], '()');
826
827 if (lastParenIndex > -1) {
828 var start = cap[0].indexOf('!') === 0 ? 5 : 4;
829 var linkLen = start + cap[1].length + lastParenIndex;
830 cap[2] = cap[2].substring(0, lastParenIndex);
831 cap[0] = cap[0].substring(0, linkLen).trim();
832 cap[3] = '';
833 }
834
835 var href = cap[2];
836 var title = '';
837
838 if (this.options.pedantic) {
839 var link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
840
841 if (link) {
842 href = link[1];
843 title = link[3];
844 } else {
845 title = '';
846 }
847 } else {
848 title = cap[3] ? cap[3].slice(1, -1) : '';
849 }
850
851 href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
852 var token = outputLink(cap, {
853 href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
854 title: title ? title.replace(this.rules.inline._escapes, '$1') : title
855 }, cap[0]);
856 return token;
857 }
858 };
859
860 _proto.reflink = function reflink(src, links) {
861 var cap;
862
863 if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
864 var link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
865 link = links[link.toLowerCase()];
866
867 if (!link || !link.href) {
868 var text = cap[0].charAt(0);
869 return {
870 type: 'text',
871 raw: text,
872 text: text
873 };
874 }
875
876 var token = outputLink(cap, link, cap[0]);
877 return token;
878 }
879 };
880
881 _proto.strong = function strong(src) {
882 var cap = this.rules.inline.strong.exec(src);
883
884 if (cap) {
885 return {
886 type: 'strong',
887 raw: cap[0],
888 text: cap[4] || cap[3] || cap[2] || cap[1]
889 };
890 }
891 };
892
893 _proto.em = function em(src) {
894 var cap = this.rules.inline.em.exec(src);
895
896 if (cap) {
897 return {
898 type: 'em',
899 raw: cap[0],
900 text: cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]
901 };
902 }
903 };
904
905 _proto.codespan = function codespan(src) {
906 var cap = this.rules.inline.code.exec(src);
907
908 if (cap) {
909 var text = cap[2].replace(/\n/g, ' ');
910 var hasNonSpaceChars = /[^ ]/.test(text);
911 var hasSpaceCharsOnBothEnds = text.startsWith(' ') && text.endsWith(' ');
912
913 if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
914 text = text.substring(1, text.length - 1);
915 }
916
917 text = _escape(text, true);
918 return {
919 type: 'codespan',
920 raw: cap[0],
921 text: text
922 };
923 }
924 };
925
926 _proto.br = function br(src) {
927 var cap = this.rules.inline.br.exec(src);
928
929 if (cap) {
930 return {
931 type: 'br',
932 raw: cap[0]
933 };
934 }
935 };
936
937 _proto.del = function del(src) {
938 var cap = this.rules.inline.del.exec(src);
939
940 if (cap) {
941 return {
942 type: 'del',
943 raw: cap[0],
944 text: cap[1]
945 };
946 }
947 };
948
949 _proto.autolink = function autolink(src, mangle) {
950 var cap = this.rules.inline.autolink.exec(src);
951
952 if (cap) {
953 var text, href;
954
955 if (cap[2] === '@') {
956 text = _escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
957 href = 'mailto:' + text;
958 } else {
959 text = _escape(cap[1]);
960 href = text;
961 }
962
963 return {
964 type: 'link',
965 raw: cap[0],
966 text: text,
967 href: href,
968 tokens: [{
969 type: 'text',
970 raw: text,
971 text: text
972 }]
973 };
974 }
975 };
976
977 _proto.url = function url(src, mangle) {
978 var cap;
979
980 if (cap = this.rules.inline.url.exec(src)) {
981 var text, href;
982
983 if (cap[2] === '@') {
984 text = _escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
985 href = 'mailto:' + text;
986 } else {
987 // do extended autolink path validation
988 var prevCapZero;
989
990 do {
991 prevCapZero = cap[0];
992 cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
993 } while (prevCapZero !== cap[0]);
994
995 text = _escape(cap[0]);
996
997 if (cap[1] === 'www.') {
998 href = 'http://' + text;
999 } else {
1000 href = text;
1001 }
1002 }
1003
1004 return {
1005 type: 'link',
1006 raw: cap[0],
1007 text: text,
1008 href: href,
1009 tokens: [{
1010 type: 'text',
1011 raw: text,
1012 text: text
1013 }]
1014 };
1015 }
1016 };
1017
1018 _proto.inlineText = function inlineText(src, inRawBlock, smartypants) {
1019 var cap = this.rules.inline.text.exec(src);
1020
1021 if (cap) {
1022 var text;
1023
1024 if (inRawBlock) {
1025 text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0];
1026 } else {
1027 text = _escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
1028 }
1029
1030 return {
1031 type: 'text',
1032 raw: cap[0],
1033 text: text
1034 };
1035 }
1036 };
1037
1038 return Tokenizer;
1039 }();
1040
1041 var noopTest$1 = helpers.noopTest,
1042 edit$1 = helpers.edit,
1043 merge$1 = helpers.merge;
1044 /**
1045 * Block-Level Grammar
1046 */
1047
1048 var block = {
1049 newline: /^\n+/,
1050 code: /^( {4}[^\n]+\n*)+/,
1051 fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
1052 hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
1053 heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
1054 blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
1055 list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
1056 html: '^ {0,3}(?:' // optional indentation
1057 + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
1058 + '|comment[^\\n]*(\\n+|$)' // (2)
1059 + '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
1060 + '|<![A-Z][\\s\\S]*?>\\n*' // (4)
1061 + '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5)
1062 + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
1063 + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
1064 + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
1065 + ')',
1066 def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
1067 nptable: noopTest$1,
1068 table: noopTest$1,
1069 lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
1070 // regex template, placeholders will be replaced according to different paragraph
1071 // interruption rules of commonmark and the original markdown spec:
1072 _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,
1073 text: /^[^\n]+/
1074 };
1075 block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
1076 block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
1077 block.def = edit$1(block.def).replace('label', block._label).replace('title', block._title).getRegex();
1078 block.bullet = /(?:[*+-]|\d{1,9}\.)/;
1079 block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
1080 block.item = edit$1(block.item, 'gm').replace(/bull/g, block.bullet).getRegex();
1081 block.list = edit$1(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex();
1082 block._tag = 'address|article|aside|base|basefont|blockquote|body|caption' + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption' + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe' + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option' + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr' + '|track|ul';
1083 block._comment = /<!--(?!-?>)[\s\S]*?-->/;
1084 block.html = edit$1(block.html, 'i').replace('comment', block._comment).replace('tag', block._tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
1085 block.paragraph = edit$1(block._paragraph).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} ').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
1086 .replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1087 .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
1088 .getRegex();
1089 block.blockquote = edit$1(block.blockquote).replace('paragraph', block.paragraph).getRegex();
1090 /**
1091 * Normal Block Grammar
1092 */
1093
1094 block.normal = merge$1({}, block);
1095 /**
1096 * GFM Block Grammar
1097 */
1098
1099 block.gfm = merge$1({}, block.normal, {
1100 nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
1101 + ' *([-:]+ *\\|[-| :]*)' // Align
1102 + '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)',
1103 // Cells
1104 table: '^ *\\|(.+)\\n' // Header
1105 + ' *\\|?( *[-:]+[-| :]*)' // Align
1106 + '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
1107
1108 });
1109 block.gfm.nptable = edit$1(block.gfm.nptable).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} ').replace('blockquote', ' {0,3}>').replace('code', ' {4}[^\\n]').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1110 .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
1111 .getRegex();
1112 block.gfm.table = edit$1(block.gfm.table).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} ').replace('blockquote', ' {0,3}>').replace('code', ' {4}[^\\n]').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1113 .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
1114 .getRegex();
1115 /**
1116 * Pedantic grammar (original John Gruber's loose markdown specification)
1117 */
1118
1119 block.pedantic = merge$1({}, block.normal, {
1120 html: edit$1('^ *(?:comment *(?:\\n|\\s*$)' + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
1121 + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))').replace('comment', block._comment).replace(/tag/g, '(?!(?:' + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub' + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)' + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b').getRegex(),
1122 def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
1123 heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
1124 fences: noopTest$1,
1125 // fences not supported
1126 paragraph: edit$1(block.normal._paragraph).replace('hr', block.hr).replace('heading', ' *#{1,6} *[^\n]').replace('lheading', block.lheading).replace('blockquote', ' {0,3}>').replace('|fences', '').replace('|list', '').replace('|html', '').getRegex()
1127 });
1128 /**
1129 * Inline-Level Grammar
1130 */
1131
1132 var inline = {
1133 escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
1134 autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
1135 url: noopTest$1,
1136 tag: '^comment' + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
1137 + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
1138 + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
1139 + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
1140 + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>',
1141 // CDATA section
1142 link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
1143 reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
1144 nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
1145 strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
1146 em: /^_([^\s_])_(?!_)|^_([^\s_<][\s\S]*?[^\s_])_(?!_|[^\s,punctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\s,punctuation])|^\*([^\s*<\[])\*(?!\*)|^\*([^\s<"][\s\S]*?[^\s\[\*])\*(?![\]`punctuation])|^\*([^\s*"<\[][\s\S]*[^\s])\*(?!\*)/,
1147 code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
1148 br: /^( {2,}|\\)\n(?!\s*$)/,
1149 del: noopTest$1,
1150 text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/
1151 }; // list of punctuation marks from common mark spec
1152 // without ` and ] to workaround Rule 17 (inline code blocks/links)
1153 // without , to work around example 393
1154
1155 inline._punctuation = '!"#$%&\'()*+\\-./:;<=>?@\\[^_{|}~';
1156 inline.em = edit$1(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
1157 inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
1158 inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
1159 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])?)+(?![-_])/;
1160 inline.autolink = edit$1(inline.autolink).replace('scheme', inline._scheme).replace('email', inline._email).getRegex();
1161 inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
1162 inline.tag = edit$1(inline.tag).replace('comment', block._comment).replace('attribute', inline._attribute).getRegex();
1163 inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
1164 inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
1165 inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
1166 inline.link = edit$1(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex();
1167 inline.reflink = edit$1(inline.reflink).replace('label', inline._label).getRegex();
1168 /**
1169 * Normal Inline Grammar
1170 */
1171
1172 inline.normal = merge$1({}, inline);
1173 /**
1174 * Pedantic Inline Grammar
1175 */
1176
1177 inline.pedantic = merge$1({}, inline.normal, {
1178 strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
1179 em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
1180 link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(),
1181 reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex()
1182 });
1183 /**
1184 * GFM Inline Grammar
1185 */
1186
1187 inline.gfm = merge$1({}, inline.normal, {
1188 escape: edit$1(inline.escape).replace('])', '~|])').getRegex(),
1189 _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
1190 url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
1191 _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
1192 del: /^~+(?=\S)([\s\S]*?\S)~+/,
1193 text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
1194 });
1195 inline.gfm.url = edit$1(inline.gfm.url, 'i').replace('email', inline.gfm._extended_email).getRegex();
1196 /**
1197 * GFM + Line Breaks Inline Grammar
1198 */
1199
1200 inline.breaks = merge$1({}, inline.gfm, {
1201 br: edit$1(inline.br).replace('{2,}', '*').getRegex(),
1202 text: edit$1(inline.gfm.text).replace('\\b_', '\\b_| {2,}\\n').replace(/\{2,\}/g, '*').getRegex()
1203 });
1204 var rules = {
1205 block: block,
1206 inline: inline
1207 };
1208
1209 var defaults$2 = defaults.defaults;
1210 var block$1 = rules.block,
1211 inline$1 = rules.inline;
1212 /**
1213 * smartypants text replacement
1214 */
1215
1216 function smartypants(text) {
1217 return text // em-dashes
1218 .replace(/---/g, "\u2014") // en-dashes
1219 .replace(/--/g, "\u2013") // opening singles
1220 .replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // closing singles & apostrophes
1221 .replace(/'/g, "\u2019") // opening doubles
1222 .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C") // closing doubles
1223 .replace(/"/g, "\u201D") // ellipses
1224 .replace(/\.{3}/g, "\u2026");
1225 }
1226 /**
1227 * mangle email addresses
1228 */
1229
1230
1231 function mangle(text) {
1232 var out = '',
1233 i,
1234 ch;
1235 var l = text.length;
1236
1237 for (i = 0; i < l; i++) {
1238 ch = text.charCodeAt(i);
1239
1240 if (Math.random() > 0.5) {
1241 ch = 'x' + ch.toString(16);
1242 }
1243
1244 out += '&#' + ch + ';';
1245 }
1246
1247 return out;
1248 }
1249 /**
1250 * Block Lexer
1251 */
1252
1253
1254 var Lexer_1 = /*#__PURE__*/function () {
1255 function Lexer(options) {
1256 this.tokens = [];
1257 this.tokens.links = Object.create(null);
1258 this.options = options || defaults$2;
1259 this.options.tokenizer = this.options.tokenizer || new Tokenizer_1();
1260 this.tokenizer = this.options.tokenizer;
1261 this.tokenizer.options = this.options;
1262 var rules = {
1263 block: block$1.normal,
1264 inline: inline$1.normal
1265 };
1266
1267 if (this.options.pedantic) {
1268 rules.block = block$1.pedantic;
1269 rules.inline = inline$1.pedantic;
1270 } else if (this.options.gfm) {
1271 rules.block = block$1.gfm;
1272
1273 if (this.options.breaks) {
1274 rules.inline = inline$1.breaks;
1275 } else {
1276 rules.inline = inline$1.gfm;
1277 }
1278 }
1279
1280 this.tokenizer.rules = rules;
1281 }
1282 /**
1283 * Expose Rules
1284 */
1285
1286
1287 /**
1288 * Static Lex Method
1289 */
1290 Lexer.lex = function lex(src, options) {
1291 var lexer = new Lexer(options);
1292 return lexer.lex(src);
1293 }
1294 /**
1295 * Preprocessing
1296 */
1297 ;
1298
1299 var _proto = Lexer.prototype;
1300
1301 _proto.lex = function lex(src) {
1302 src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ');
1303 this.blockTokens(src, this.tokens, true);
1304 this.inline(this.tokens);
1305 return this.tokens;
1306 }
1307 /**
1308 * Lexing
1309 */
1310 ;
1311
1312 _proto.blockTokens = function blockTokens(src, tokens, top) {
1313 if (tokens === void 0) {
1314 tokens = [];
1315 }
1316
1317 if (top === void 0) {
1318 top = true;
1319 }
1320
1321 src = src.replace(/^ +$/gm, '');
1322 var token, i, l, lastToken;
1323
1324 while (src) {
1325 // newline
1326 if (token = this.tokenizer.space(src)) {
1327 src = src.substring(token.raw.length);
1328
1329 if (token.type) {
1330 tokens.push(token);
1331 }
1332
1333 continue;
1334 } // code
1335
1336
1337 if (token = this.tokenizer.code(src, tokens)) {
1338 src = src.substring(token.raw.length);
1339
1340 if (token.type) {
1341 tokens.push(token);
1342 } else {
1343 lastToken = tokens[tokens.length - 1];
1344 lastToken.raw += '\n' + token.raw;
1345 lastToken.text += '\n' + token.text;
1346 }
1347
1348 continue;
1349 } // fences
1350
1351
1352 if (token = this.tokenizer.fences(src)) {
1353 src = src.substring(token.raw.length);
1354 tokens.push(token);
1355 continue;
1356 } // heading
1357
1358
1359 if (token = this.tokenizer.heading(src)) {
1360 src = src.substring(token.raw.length);
1361 tokens.push(token);
1362 continue;
1363 } // table no leading pipe (gfm)
1364
1365
1366 if (token = this.tokenizer.nptable(src)) {
1367 src = src.substring(token.raw.length);
1368 tokens.push(token);
1369 continue;
1370 } // hr
1371
1372
1373 if (token = this.tokenizer.hr(src)) {
1374 src = src.substring(token.raw.length);
1375 tokens.push(token);
1376 continue;
1377 } // blockquote
1378
1379
1380 if (token = this.tokenizer.blockquote(src)) {
1381 src = src.substring(token.raw.length);
1382 token.tokens = this.blockTokens(token.text, [], top);
1383 tokens.push(token);
1384 continue;
1385 } // list
1386
1387
1388 if (token = this.tokenizer.list(src)) {
1389 src = src.substring(token.raw.length);
1390 l = token.items.length;
1391
1392 for (i = 0; i < l; i++) {
1393 token.items[i].tokens = this.blockTokens(token.items[i].text, [], false);
1394 }
1395
1396 tokens.push(token);
1397 continue;
1398 } // html
1399
1400
1401 if (token = this.tokenizer.html(src)) {
1402 src = src.substring(token.raw.length);
1403 tokens.push(token);
1404 continue;
1405 } // def
1406
1407
1408 if (top && (token = this.tokenizer.def(src))) {
1409 src = src.substring(token.raw.length);
1410
1411 if (!this.tokens.links[token.tag]) {
1412 this.tokens.links[token.tag] = {
1413 href: token.href,
1414 title: token.title
1415 };
1416 }
1417
1418 continue;
1419 } // table (gfm)
1420
1421
1422 if (token = this.tokenizer.table(src)) {
1423 src = src.substring(token.raw.length);
1424 tokens.push(token);
1425 continue;
1426 } // lheading
1427
1428
1429 if (token = this.tokenizer.lheading(src)) {
1430 src = src.substring(token.raw.length);
1431 tokens.push(token);
1432 continue;
1433 } // top-level paragraph
1434
1435
1436 if (top && (token = this.tokenizer.paragraph(src))) {
1437 src = src.substring(token.raw.length);
1438 tokens.push(token);
1439 continue;
1440 } // text
1441
1442
1443 if (token = this.tokenizer.text(src, tokens)) {
1444 src = src.substring(token.raw.length);
1445
1446 if (token.type) {
1447 tokens.push(token);
1448 } else {
1449 lastToken = tokens[tokens.length - 1];
1450 lastToken.raw += '\n' + token.raw;
1451 lastToken.text += '\n' + token.text;
1452 }
1453
1454 continue;
1455 }
1456
1457 if (src) {
1458 var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1459
1460 if (this.options.silent) {
1461 console.error(errMsg);
1462 break;
1463 } else {
1464 throw new Error(errMsg);
1465 }
1466 }
1467 }
1468
1469 return tokens;
1470 };
1471
1472 _proto.inline = function inline(tokens) {
1473 var i, j, k, l2, row, token;
1474 var l = tokens.length;
1475
1476 for (i = 0; i < l; i++) {
1477 token = tokens[i];
1478
1479 switch (token.type) {
1480 case 'paragraph':
1481 case 'text':
1482 case 'heading':
1483 {
1484 token.tokens = [];
1485 this.inlineTokens(token.text, token.tokens);
1486 break;
1487 }
1488
1489 case 'table':
1490 {
1491 token.tokens = {
1492 header: [],
1493 cells: []
1494 }; // header
1495
1496 l2 = token.header.length;
1497
1498 for (j = 0; j < l2; j++) {
1499 token.tokens.header[j] = [];
1500 this.inlineTokens(token.header[j], token.tokens.header[j]);
1501 } // cells
1502
1503
1504 l2 = token.cells.length;
1505
1506 for (j = 0; j < l2; j++) {
1507 row = token.cells[j];
1508 token.tokens.cells[j] = [];
1509
1510 for (k = 0; k < row.length; k++) {
1511 token.tokens.cells[j][k] = [];
1512 this.inlineTokens(row[k], token.tokens.cells[j][k]);
1513 }
1514 }
1515
1516 break;
1517 }
1518
1519 case 'blockquote':
1520 {
1521 this.inline(token.tokens);
1522 break;
1523 }
1524
1525 case 'list':
1526 {
1527 l2 = token.items.length;
1528
1529 for (j = 0; j < l2; j++) {
1530 this.inline(token.items[j].tokens);
1531 }
1532
1533 break;
1534 }
1535 }
1536 }
1537
1538 return tokens;
1539 }
1540 /**
1541 * Lexing/Compiling
1542 */
1543 ;
1544
1545 _proto.inlineTokens = function inlineTokens(src, tokens, inLink, inRawBlock) {
1546 if (tokens === void 0) {
1547 tokens = [];
1548 }
1549
1550 if (inLink === void 0) {
1551 inLink = false;
1552 }
1553
1554 if (inRawBlock === void 0) {
1555 inRawBlock = false;
1556 }
1557
1558 var token;
1559
1560 while (src) {
1561 // escape
1562 if (token = this.tokenizer.escape(src)) {
1563 src = src.substring(token.raw.length);
1564 tokens.push(token);
1565 continue;
1566 } // tag
1567
1568
1569 if (token = this.tokenizer.tag(src, inLink, inRawBlock)) {
1570 src = src.substring(token.raw.length);
1571 inLink = token.inLink;
1572 inRawBlock = token.inRawBlock;
1573 tokens.push(token);
1574 continue;
1575 } // link
1576
1577
1578 if (token = this.tokenizer.link(src)) {
1579 src = src.substring(token.raw.length);
1580
1581 if (token.type === 'link') {
1582 token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
1583 }
1584
1585 tokens.push(token);
1586 continue;
1587 } // reflink, nolink
1588
1589
1590 if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1591 src = src.substring(token.raw.length);
1592
1593 if (token.type === 'link') {
1594 token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
1595 }
1596
1597 tokens.push(token);
1598 continue;
1599 } // strong
1600
1601
1602 if (token = this.tokenizer.strong(src)) {
1603 src = src.substring(token.raw.length);
1604 token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1605 tokens.push(token);
1606 continue;
1607 } // em
1608
1609
1610 if (token = this.tokenizer.em(src)) {
1611 src = src.substring(token.raw.length);
1612 token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1613 tokens.push(token);
1614 continue;
1615 } // code
1616
1617
1618 if (token = this.tokenizer.codespan(src)) {
1619 src = src.substring(token.raw.length);
1620 tokens.push(token);
1621 continue;
1622 } // br
1623
1624
1625 if (token = this.tokenizer.br(src)) {
1626 src = src.substring(token.raw.length);
1627 tokens.push(token);
1628 continue;
1629 } // del (gfm)
1630
1631
1632 if (token = this.tokenizer.del(src)) {
1633 src = src.substring(token.raw.length);
1634 token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1635 tokens.push(token);
1636 continue;
1637 } // autolink
1638
1639
1640 if (token = this.tokenizer.autolink(src, mangle)) {
1641 src = src.substring(token.raw.length);
1642 tokens.push(token);
1643 continue;
1644 } // url (gfm)
1645
1646
1647 if (!inLink && (token = this.tokenizer.url(src, mangle))) {
1648 src = src.substring(token.raw.length);
1649 tokens.push(token);
1650 continue;
1651 } // text
1652
1653
1654 if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) {
1655 src = src.substring(token.raw.length);
1656 tokens.push(token);
1657 continue;
1658 }
1659
1660 if (src) {
1661 var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1662
1663 if (this.options.silent) {
1664 console.error(errMsg);
1665 break;
1666 } else {
1667 throw new Error(errMsg);
1668 }
1669 }
1670 }
1671
1672 return tokens;
1673 };
1674
1675 _createClass(Lexer, null, [{
1676 key: "rules",
1677 get: function get() {
1678 return {
1679 block: block$1,
1680 inline: inline$1
1681 };
1682 }
1683 }]);
1684
1685 return Lexer;
1686 }();
1687
1688 var defaults$3 = defaults.defaults;
1689 var cleanUrl$1 = helpers.cleanUrl,
1690 escape$1 = helpers.escape;
1691 /**
1692 * Renderer
1693 */
1694
1695 var Renderer_1 = /*#__PURE__*/function () {
1696 function Renderer(options) {
1697 this.options = options || defaults$3;
1698 }
1699
1700 var _proto = Renderer.prototype;
1701
1702 _proto.code = function code(_code, infostring, escaped) {
1703 var lang = (infostring || '').match(/\S*/)[0];
1704
1705 if (this.options.highlight) {
1706 var out = this.options.highlight(_code, lang);
1707
1708 if (out != null && out !== _code) {
1709 escaped = true;
1710 _code = out;
1711 }
1712 }
1713
1714 if (!lang) {
1715 return '<pre><code>' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>\n';
1716 }
1717
1718 return '<pre><code class="' + this.options.langPrefix + escape$1(lang, true) + '">' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>\n';
1719 };
1720
1721 _proto.blockquote = function blockquote(quote) {
1722 return '<blockquote>\n' + quote + '</blockquote>\n';
1723 };
1724
1725 _proto.html = function html(_html) {
1726 return _html;
1727 };
1728
1729 _proto.heading = function heading(text, level, raw, slugger) {
1730 if (this.options.headerIds) {
1731 return '<h' + level + ' id="' + this.options.headerPrefix + slugger.slug(raw) + '">' + text + '</h' + level + '>\n';
1732 } // ignore IDs
1733
1734
1735 return '<h' + level + '>' + text + '</h' + level + '>\n';
1736 };
1737
1738 _proto.hr = function hr() {
1739 return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
1740 };
1741
1742 _proto.list = function list(body, ordered, start) {
1743 var type = ordered ? 'ol' : 'ul',
1744 startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
1745 return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
1746 };
1747
1748 _proto.listitem = function listitem(text) {
1749 return '<li>' + text + '</li>\n';
1750 };
1751
1752 _proto.checkbox = function checkbox(checked) {
1753 return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
1754 };
1755
1756 _proto.paragraph = function paragraph(text) {
1757 return '<p>' + text + '</p>\n';
1758 };
1759
1760 _proto.table = function table(header, body) {
1761 if (body) body = '<tbody>' + body + '</tbody>';
1762 return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
1763 };
1764
1765 _proto.tablerow = function tablerow(content) {
1766 return '<tr>\n' + content + '</tr>\n';
1767 };
1768
1769 _proto.tablecell = function tablecell(content, flags) {
1770 var type = flags.header ? 'th' : 'td';
1771 var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>';
1772 return tag + content + '</' + type + '>\n';
1773 } // span level renderer
1774 ;
1775
1776 _proto.strong = function strong(text) {
1777 return '<strong>' + text + '</strong>';
1778 };
1779
1780 _proto.em = function em(text) {
1781 return '<em>' + text + '</em>';
1782 };
1783
1784 _proto.codespan = function codespan(text) {
1785 return '<code>' + text + '</code>';
1786 };
1787
1788 _proto.br = function br() {
1789 return this.options.xhtml ? '<br/>' : '<br>';
1790 };
1791
1792 _proto.del = function del(text) {
1793 return '<del>' + text + '</del>';
1794 };
1795
1796 _proto.link = function link(href, title, text) {
1797 href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
1798
1799 if (href === null) {
1800 return text;
1801 }
1802
1803 var out = '<a href="' + escape$1(href) + '"';
1804
1805 if (title) {
1806 out += ' title="' + title + '"';
1807 }
1808
1809 out += '>' + text + '</a>';
1810 return out;
1811 };
1812
1813 _proto.image = function image(href, title, text) {
1814 href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
1815
1816 if (href === null) {
1817 return text;
1818 }
1819
1820 var out = '<img src="' + href + '" alt="' + text + '"';
1821
1822 if (title) {
1823 out += ' title="' + title + '"';
1824 }
1825
1826 out += this.options.xhtml ? '/>' : '>';
1827 return out;
1828 };
1829
1830 _proto.text = function text(_text) {
1831 return _text;
1832 };
1833
1834 return Renderer;
1835 }();
1836
1837 /**
1838 * TextRenderer
1839 * returns only the textual part of the token
1840 */
1841 var TextRenderer_1 = /*#__PURE__*/function () {
1842 function TextRenderer() {}
1843
1844 var _proto = TextRenderer.prototype;
1845
1846 // no need for block level renderers
1847 _proto.strong = function strong(text) {
1848 return text;
1849 };
1850
1851 _proto.em = function em(text) {
1852 return text;
1853 };
1854
1855 _proto.codespan = function codespan(text) {
1856 return text;
1857 };
1858
1859 _proto.del = function del(text) {
1860 return text;
1861 };
1862
1863 _proto.html = function html(text) {
1864 return text;
1865 };
1866
1867 _proto.text = function text(_text) {
1868 return _text;
1869 };
1870
1871 _proto.link = function link(href, title, text) {
1872 return '' + text;
1873 };
1874
1875 _proto.image = function image(href, title, text) {
1876 return '' + text;
1877 };
1878
1879 _proto.br = function br() {
1880 return '';
1881 };
1882
1883 return TextRenderer;
1884 }();
1885
1886 /**
1887 * Slugger generates header id
1888 */
1889 var Slugger_1 = /*#__PURE__*/function () {
1890 function Slugger() {
1891 this.seen = {};
1892 }
1893 /**
1894 * Convert string to unique id
1895 */
1896
1897
1898 var _proto = Slugger.prototype;
1899
1900 _proto.slug = function slug(value) {
1901 var slug = value.toLowerCase().trim() // remove html tags
1902 .replace(/<[!\/a-z].*?>/ig, '') // remove unwanted chars
1903 .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
1904
1905 if (this.seen.hasOwnProperty(slug)) {
1906 var originalSlug = slug;
1907
1908 do {
1909 this.seen[originalSlug]++;
1910 slug = originalSlug + '-' + this.seen[originalSlug];
1911 } while (this.seen.hasOwnProperty(slug));
1912 }
1913
1914 this.seen[slug] = 0;
1915 return slug;
1916 };
1917
1918 return Slugger;
1919 }();
1920
1921 var defaults$4 = defaults.defaults;
1922 var unescape$1 = helpers.unescape;
1923 /**
1924 * Parsing & Compiling
1925 */
1926
1927 var Parser_1 = /*#__PURE__*/function () {
1928 function Parser(options) {
1929 this.options = options || defaults$4;
1930 this.options.renderer = this.options.renderer || new Renderer_1();
1931 this.renderer = this.options.renderer;
1932 this.renderer.options = this.options;
1933 this.textRenderer = new TextRenderer_1();
1934 this.slugger = new Slugger_1();
1935 }
1936 /**
1937 * Static Parse Method
1938 */
1939
1940
1941 Parser.parse = function parse(tokens, options) {
1942 var parser = new Parser(options);
1943 return parser.parse(tokens);
1944 }
1945 /**
1946 * Parse Loop
1947 */
1948 ;
1949
1950 var _proto = Parser.prototype;
1951
1952 _proto.parse = function parse(tokens, top) {
1953 if (top === void 0) {
1954 top = true;
1955 }
1956
1957 var out = '',
1958 i,
1959 j,
1960 k,
1961 l2,
1962 l3,
1963 row,
1964 cell,
1965 header,
1966 body,
1967 token,
1968 ordered,
1969 start,
1970 loose,
1971 itemBody,
1972 item,
1973 checked,
1974 task,
1975 checkbox;
1976 var l = tokens.length;
1977
1978 for (i = 0; i < l; i++) {
1979 token = tokens[i];
1980
1981 switch (token.type) {
1982 case 'space':
1983 {
1984 continue;
1985 }
1986
1987 case 'hr':
1988 {
1989 out += this.renderer.hr();
1990 continue;
1991 }
1992
1993 case 'heading':
1994 {
1995 out += this.renderer.heading(this.parseInline(token.tokens), token.depth, unescape$1(this.parseInline(token.tokens, this.textRenderer)), this.slugger);
1996 continue;
1997 }
1998
1999 case 'code':
2000 {
2001 out += this.renderer.code(token.text, token.lang, token.escaped);
2002 continue;
2003 }
2004
2005 case 'table':
2006 {
2007 header = ''; // header
2008
2009 cell = '';
2010 l2 = token.header.length;
2011
2012 for (j = 0; j < l2; j++) {
2013 cell += this.renderer.tablecell(this.parseInline(token.tokens.header[j]), {
2014 header: true,
2015 align: token.align[j]
2016 });
2017 }
2018
2019 header += this.renderer.tablerow(cell);
2020 body = '';
2021 l2 = token.cells.length;
2022
2023 for (j = 0; j < l2; j++) {
2024 row = token.tokens.cells[j];
2025 cell = '';
2026 l3 = row.length;
2027
2028 for (k = 0; k < l3; k++) {
2029 cell += this.renderer.tablecell(this.parseInline(row[k]), {
2030 header: false,
2031 align: token.align[k]
2032 });
2033 }
2034
2035 body += this.renderer.tablerow(cell);
2036 }
2037
2038 out += this.renderer.table(header, body);
2039 continue;
2040 }
2041
2042 case 'blockquote':
2043 {
2044 body = this.parse(token.tokens);
2045 out += this.renderer.blockquote(body);
2046 continue;
2047 }
2048
2049 case 'list':
2050 {
2051 ordered = token.ordered;
2052 start = token.start;
2053 loose = token.loose;
2054 l2 = token.items.length;
2055 body = '';
2056
2057 for (j = 0; j < l2; j++) {
2058 item = token.items[j];
2059 checked = item.checked;
2060 task = item.task;
2061 itemBody = '';
2062
2063 if (item.task) {
2064 checkbox = this.renderer.checkbox(checked);
2065
2066 if (loose) {
2067 if (item.tokens.length > 0 && item.tokens[0].type === 'text') {
2068 item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
2069
2070 if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
2071 item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
2072 }
2073 } else {
2074 item.tokens.unshift({
2075 type: 'text',
2076 text: checkbox
2077 });
2078 }
2079 } else {
2080 itemBody += checkbox;
2081 }
2082 }
2083
2084 itemBody += this.parse(item.tokens, loose);
2085 body += this.renderer.listitem(itemBody, task, checked);
2086 }
2087
2088 out += this.renderer.list(body, ordered, start);
2089 continue;
2090 }
2091
2092 case 'html':
2093 {
2094 // TODO parse inline content if parameter markdown=1
2095 out += this.renderer.html(token.text);
2096 continue;
2097 }
2098
2099 case 'paragraph':
2100 {
2101 out += this.renderer.paragraph(this.parseInline(token.tokens));
2102 continue;
2103 }
2104
2105 case 'text':
2106 {
2107 body = token.tokens ? this.parseInline(token.tokens) : token.text;
2108
2109 while (i + 1 < l && tokens[i + 1].type === 'text') {
2110 token = tokens[++i];
2111 body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
2112 }
2113
2114 out += top ? this.renderer.paragraph(body) : body;
2115 continue;
2116 }
2117
2118 default:
2119 {
2120 var errMsg = 'Token with "' + token.type + '" type was not found.';
2121
2122 if (this.options.silent) {
2123 console.error(errMsg);
2124 return;
2125 } else {
2126 throw new Error(errMsg);
2127 }
2128 }
2129 }
2130 }
2131
2132 return out;
2133 }
2134 /**
2135 * Parse Inline Tokens
2136 */
2137 ;
2138
2139 _proto.parseInline = function parseInline(tokens, renderer) {
2140 renderer = renderer || this.renderer;
2141 var out = '',
2142 i,
2143 token;
2144 var l = tokens.length;
2145
2146 for (i = 0; i < l; i++) {
2147 token = tokens[i];
2148
2149 switch (token.type) {
2150 case 'escape':
2151 {
2152 out += renderer.text(token.text);
2153 break;
2154 }
2155
2156 case 'html':
2157 {
2158 out += renderer.html(token.text);
2159 break;
2160 }
2161
2162 case 'link':
2163 {
2164 out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
2165 break;
2166 }
2167
2168 case 'image':
2169 {
2170 out += renderer.image(token.href, token.title, token.text);
2171 break;
2172 }
2173
2174 case 'strong':
2175 {
2176 out += renderer.strong(this.parseInline(token.tokens, renderer));
2177 break;
2178 }
2179
2180 case 'em':
2181 {
2182 out += renderer.em(this.parseInline(token.tokens, renderer));
2183 break;
2184 }
2185
2186 case 'codespan':
2187 {
2188 out += renderer.codespan(token.text);
2189 break;
2190 }
2191
2192 case 'br':
2193 {
2194 out += renderer.br();
2195 break;
2196 }
2197
2198 case 'del':
2199 {
2200 out += renderer.del(this.parseInline(token.tokens, renderer));
2201 break;
2202 }
2203
2204 case 'text':
2205 {
2206 out += renderer.text(token.text);
2207 break;
2208 }
2209
2210 default:
2211 {
2212 var errMsg = 'Token with "' + token.type + '" type was not found.';
2213
2214 if (this.options.silent) {
2215 console.error(errMsg);
2216 return;
2217 } else {
2218 throw new Error(errMsg);
2219 }
2220 }
2221 }
2222 }
2223
2224 return out;
2225 };
2226
2227 return Parser;
2228 }();
2229
2230 var merge$2 = helpers.merge,
2231 checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation,
2232 escape$2 = helpers.escape;
2233 var getDefaults = defaults.getDefaults,
2234 changeDefaults = defaults.changeDefaults,
2235 defaults$5 = defaults.defaults;
2236 /**
2237 * Marked
2238 */
2239
2240 function marked(src, opt, callback) {
2241 // throw error in case of non string input
2242 if (typeof src === 'undefined' || src === null) {
2243 throw new Error('marked(): input parameter is undefined or null');
2244 }
2245
2246 if (typeof src !== 'string') {
2247 throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
2248 }
2249
2250 if (typeof opt === 'function') {
2251 callback = opt;
2252 opt = null;
2253 }
2254
2255 opt = merge$2({}, marked.defaults, opt || {});
2256 checkSanitizeDeprecation$1(opt);
2257
2258 if (callback) {
2259 var highlight = opt.highlight;
2260 var tokens;
2261
2262 try {
2263 tokens = Lexer_1.lex(src, opt);
2264 } catch (e) {
2265 return callback(e);
2266 }
2267
2268 var done = function done(err) {
2269 var out;
2270
2271 if (!err) {
2272 try {
2273 out = Parser_1.parse(tokens, opt);
2274 } catch (e) {
2275 err = e;
2276 }
2277 }
2278
2279 opt.highlight = highlight;
2280 return err ? callback(err) : callback(null, out);
2281 };
2282
2283 if (!highlight || highlight.length < 3) {
2284 return done();
2285 }
2286
2287 delete opt.highlight;
2288 if (!tokens.length) return done();
2289 var pending = 0;
2290 marked.walkTokens(tokens, function (token) {
2291 if (token.type === 'code') {
2292 pending++;
2293 highlight(token.text, token.lang, function (err, code) {
2294 if (err) {
2295 return done(err);
2296 }
2297
2298 if (code != null && code !== token.text) {
2299 token.text = code;
2300 token.escaped = true;
2301 }
2302
2303 pending--;
2304
2305 if (pending === 0) {
2306 done();
2307 }
2308 });
2309 }
2310 });
2311
2312 if (pending === 0) {
2313 done();
2314 }
2315
2316 return;
2317 }
2318
2319 try {
2320 var _tokens = Lexer_1.lex(src, opt);
2321
2322 if (opt.walkTokens) {
2323 marked.walkTokens(_tokens, opt.walkTokens);
2324 }
2325
2326 return Parser_1.parse(_tokens, opt);
2327 } catch (e) {
2328 e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2329
2330 if (opt.silent) {
2331 return '<p>An error occurred:</p><pre>' + escape$2(e.message + '', true) + '</pre>';
2332 }
2333
2334 throw e;
2335 }
2336 }
2337 /**
2338 * Options
2339 */
2340
2341
2342 marked.options = marked.setOptions = function (opt) {
2343 merge$2(marked.defaults, opt);
2344 changeDefaults(marked.defaults);
2345 return marked;
2346 };
2347
2348 marked.getDefaults = getDefaults;
2349 marked.defaults = defaults$5;
2350 /**
2351 * Use Extension
2352 */
2353
2354 marked.use = function (extension) {
2355 var opts = merge$2({}, extension);
2356
2357 if (extension.renderer) {
2358 (function () {
2359 var renderer = marked.defaults.renderer || new Renderer_1();
2360
2361 var _loop = function _loop(prop) {
2362 var prevRenderer = renderer[prop];
2363
2364 renderer[prop] = function () {
2365 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2366 args[_key] = arguments[_key];
2367 }
2368
2369 var ret = extension.renderer[prop].apply(renderer, args);
2370
2371 if (ret === false) {
2372 ret = prevRenderer.apply(renderer, args);
2373 }
2374
2375 return ret;
2376 };
2377 };
2378
2379 for (var prop in extension.renderer) {
2380 _loop(prop);
2381 }
2382
2383 opts.renderer = renderer;
2384 })();
2385 }
2386
2387 if (extension.tokenizer) {
2388 (function () {
2389 var tokenizer = marked.defaults.tokenizer || new Tokenizer_1();
2390
2391 var _loop2 = function _loop2(prop) {
2392 var prevTokenizer = tokenizer[prop];
2393
2394 tokenizer[prop] = function () {
2395 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2396 args[_key2] = arguments[_key2];
2397 }
2398
2399 var ret = extension.tokenizer[prop].apply(tokenizer, args);
2400
2401 if (ret === false) {
2402 ret = prevTokenizer.apply(tokenizer, args);
2403 }
2404
2405 return ret;
2406 };
2407 };
2408
2409 for (var prop in extension.tokenizer) {
2410 _loop2(prop);
2411 }
2412
2413 opts.tokenizer = tokenizer;
2414 })();
2415 }
2416
2417 if (extension.walkTokens) {
2418 var walkTokens = marked.defaults.walkTokens;
2419
2420 opts.walkTokens = function (token) {
2421 extension.walkTokens(token);
2422
2423 if (walkTokens) {
2424 walkTokens(token);
2425 }
2426 };
2427 }
2428
2429 marked.setOptions(opts);
2430 };
2431 /**
2432 * Run callback for every token
2433 */
2434
2435
2436 marked.walkTokens = function (tokens, callback) {
2437 for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
2438 var token = _step.value;
2439 callback(token);
2440
2441 switch (token.type) {
2442 case 'table':
2443 {
2444 for (var _iterator2 = _createForOfIteratorHelperLoose(token.tokens.header), _step2; !(_step2 = _iterator2()).done;) {
2445 var cell = _step2.value;
2446 marked.walkTokens(cell, callback);
2447 }
2448
2449 for (var _iterator3 = _createForOfIteratorHelperLoose(token.tokens.cells), _step3; !(_step3 = _iterator3()).done;) {
2450 var row = _step3.value;
2451
2452 for (var _iterator4 = _createForOfIteratorHelperLoose(row), _step4; !(_step4 = _iterator4()).done;) {
2453 var _cell = _step4.value;
2454 marked.walkTokens(_cell, callback);
2455 }
2456 }
2457
2458 break;
2459 }
2460
2461 case 'list':
2462 {
2463 marked.walkTokens(token.items, callback);
2464 break;
2465 }
2466
2467 default:
2468 {
2469 if (token.tokens) {
2470 marked.walkTokens(token.tokens, callback);
2471 }
2472 }
2473 }
2474 }
2475 };
2476 /**
2477 * Expose
2478 */
2479
2480
2481 marked.Parser = Parser_1;
2482 marked.parser = Parser_1.parse;
2483 marked.Renderer = Renderer_1;
2484 marked.TextRenderer = TextRenderer_1;
2485 marked.Lexer = Lexer_1;
2486 marked.lexer = Lexer_1.lex;
2487 marked.Tokenizer = Tokenizer_1;
2488 marked.Slugger = Slugger_1;
2489 marked.parse = marked;
2490 var marked_1 = marked;
2491
2492 return marked_1;
2493
2494})));