UNPKG

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