UNPKG

95.6 kBJavaScriptView Raw
1/**
2 * marked - a markdown parser
3 * Copyright (c) 2011-2022, 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' ? factory(exports) :
14 typeof define === 'function' && define.amd ? define(['exports'], factory) :
15 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.marked = {}));
16})(this, (function (exports) { '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 Object.defineProperty(Constructor, "prototype", {
32 writable: false
33 });
34 return Constructor;
35 }
36
37 function _unsupportedIterableToArray(o, minLen) {
38 if (!o) return;
39 if (typeof o === "string") return _arrayLikeToArray(o, minLen);
40 var n = Object.prototype.toString.call(o).slice(8, -1);
41 if (n === "Object" && o.constructor) n = o.constructor.name;
42 if (n === "Map" || n === "Set") return Array.from(o);
43 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
44 }
45
46 function _arrayLikeToArray(arr, len) {
47 if (len == null || len > arr.length) len = arr.length;
48
49 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
50
51 return arr2;
52 }
53
54 function _createForOfIteratorHelperLoose(o, allowArrayLike) {
55 var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
56 if (it) return (it = it.call(o)).next.bind(it);
57
58 if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
59 if (it) o = it;
60 var i = 0;
61 return function () {
62 if (i >= o.length) return {
63 done: true
64 };
65 return {
66 done: false,
67 value: o[i++]
68 };
69 };
70 }
71
72 throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
73 }
74
75 function getDefaults() {
76 return {
77 baseUrl: null,
78 breaks: false,
79 extensions: null,
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 exports.defaults = getDefaults();
99 function changeDefaults(newDefaults) {
100 exports.defaults = newDefaults;
101 }
102
103 /**
104 * Helpers
105 */
106 var escapeTest = /[&<>"']/;
107 var escapeReplace = /[&<>"']/g;
108 var escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
109 var escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
110 var escapeReplacements = {
111 '&': '&amp;',
112 '<': '&lt;',
113 '>': '&gt;',
114 '"': '&quot;',
115 "'": '&#39;'
116 };
117
118 var getEscapeReplacement = function getEscapeReplacement(ch) {
119 return escapeReplacements[ch];
120 };
121
122 function escape(html, encode) {
123 if (encode) {
124 if (escapeTest.test(html)) {
125 return html.replace(escapeReplace, getEscapeReplacement);
126 }
127 } else {
128 if (escapeTestNoEncode.test(html)) {
129 return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
130 }
131 }
132
133 return html;
134 }
135 var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
136 function unescape(html) {
137 // explicitly match decimal, hex, and named HTML entities
138 return html.replace(unescapeTest, function (_, n) {
139 n = n.toLowerCase();
140 if (n === 'colon') return ':';
141
142 if (n.charAt(0) === '#') {
143 return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
144 }
145
146 return '';
147 });
148 }
149 var caret = /(^|[^\[])\^/g;
150 function edit(regex, opt) {
151 regex = regex.source || regex;
152 opt = opt || '';
153 var obj = {
154 replace: function replace(name, val) {
155 val = val.source || val;
156 val = val.replace(caret, '$1');
157 regex = regex.replace(name, val);
158 return obj;
159 },
160 getRegex: function getRegex() {
161 return new RegExp(regex, opt);
162 }
163 };
164 return obj;
165 }
166 var nonWordAndColonTest = /[^\w:]/g;
167 var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
168 function cleanUrl(sanitize, base, href) {
169 if (sanitize) {
170 var prot;
171
172 try {
173 prot = decodeURIComponent(unescape(href)).replace(nonWordAndColonTest, '').toLowerCase();
174 } catch (e) {
175 return null;
176 }
177
178 if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
179 return null;
180 }
181 }
182
183 if (base && !originIndependentUrl.test(href)) {
184 href = resolveUrl(base, href);
185 }
186
187 try {
188 href = encodeURI(href).replace(/%25/g, '%');
189 } catch (e) {
190 return null;
191 }
192
193 return href;
194 }
195 var baseUrls = {};
196 var justDomain = /^[^:]+:\/*[^/]*$/;
197 var protocol = /^([^:]+:)[\s\S]*$/;
198 var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
199 function resolveUrl(base, href) {
200 if (!baseUrls[' ' + base]) {
201 // we can ignore everything in base after the last slash of its path component,
202 // but we might need to add _that_
203 // https://tools.ietf.org/html/rfc3986#section-3
204 if (justDomain.test(base)) {
205 baseUrls[' ' + base] = base + '/';
206 } else {
207 baseUrls[' ' + base] = rtrim(base, '/', true);
208 }
209 }
210
211 base = baseUrls[' ' + base];
212 var relativeBase = base.indexOf(':') === -1;
213
214 if (href.substring(0, 2) === '//') {
215 if (relativeBase) {
216 return href;
217 }
218
219 return base.replace(protocol, '$1') + href;
220 } else if (href.charAt(0) === '/') {
221 if (relativeBase) {
222 return href;
223 }
224
225 return base.replace(domain, '$1') + href;
226 } else {
227 return base + href;
228 }
229 }
230 var noopTest = {
231 exec: function noopTest() {}
232 };
233 function merge(obj) {
234 var i = 1,
235 target,
236 key;
237
238 for (; i < arguments.length; i++) {
239 target = arguments[i];
240
241 for (key in target) {
242 if (Object.prototype.hasOwnProperty.call(target, key)) {
243 obj[key] = target[key];
244 }
245 }
246 }
247
248 return obj;
249 }
250 function splitCells(tableRow, count) {
251 // ensure that every cell-delimiting pipe has a space
252 // before it to distinguish it from an escaped pipe
253 var row = tableRow.replace(/\|/g, function (match, offset, str) {
254 var escaped = false,
255 curr = offset;
256
257 while (--curr >= 0 && str[curr] === '\\') {
258 escaped = !escaped;
259 }
260
261 if (escaped) {
262 // odd number of slashes means | is escaped
263 // so we leave it alone
264 return '|';
265 } else {
266 // add space before unescaped |
267 return ' |';
268 }
269 }),
270 cells = row.split(/ \|/);
271 var i = 0; // First/last cell in a row cannot be empty if it has no leading/trailing pipe
272
273 if (!cells[0].trim()) {
274 cells.shift();
275 }
276
277 if (!cells[cells.length - 1].trim()) {
278 cells.pop();
279 }
280
281 if (cells.length > count) {
282 cells.splice(count);
283 } else {
284 while (cells.length < count) {
285 cells.push('');
286 }
287 }
288
289 for (; i < cells.length; i++) {
290 // leading or trailing whitespace is ignored per the gfm spec
291 cells[i] = cells[i].trim().replace(/\\\|/g, '|');
292 }
293
294 return cells;
295 } // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
296 // /c*$/ is vulnerable to REDOS.
297 // invert: Remove suffix of non-c chars instead. Default falsey.
298
299 function rtrim(str, c, invert) {
300 var l = str.length;
301
302 if (l === 0) {
303 return '';
304 } // Length of suffix matching the invert condition.
305
306
307 var suffLen = 0; // Step left until we fail to match the invert condition.
308
309 while (suffLen < l) {
310 var currChar = str.charAt(l - suffLen - 1);
311
312 if (currChar === c && !invert) {
313 suffLen++;
314 } else if (currChar !== c && invert) {
315 suffLen++;
316 } else {
317 break;
318 }
319 }
320
321 return str.substr(0, l - suffLen);
322 }
323 function findClosingBracket(str, b) {
324 if (str.indexOf(b[1]) === -1) {
325 return -1;
326 }
327
328 var l = str.length;
329 var level = 0,
330 i = 0;
331
332 for (; i < l; i++) {
333 if (str[i] === '\\') {
334 i++;
335 } else if (str[i] === b[0]) {
336 level++;
337 } else if (str[i] === b[1]) {
338 level--;
339
340 if (level < 0) {
341 return i;
342 }
343 }
344 }
345
346 return -1;
347 }
348 function checkSanitizeDeprecation(opt) {
349 if (opt && opt.sanitize && !opt.silent) {
350 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');
351 }
352 } // copied from https://stackoverflow.com/a/5450113/806777
353
354 function repeatString(pattern, count) {
355 if (count < 1) {
356 return '';
357 }
358
359 var result = '';
360
361 while (count > 1) {
362 if (count & 1) {
363 result += pattern;
364 }
365
366 count >>= 1;
367 pattern += pattern;
368 }
369
370 return result + pattern;
371 }
372
373 function outputLink(cap, link, raw, lexer) {
374 var href = link.href;
375 var title = link.title ? escape(link.title) : null;
376 var text = cap[1].replace(/\\([\[\]])/g, '$1');
377
378 if (cap[0].charAt(0) !== '!') {
379 lexer.state.inLink = true;
380 var token = {
381 type: 'link',
382 raw: raw,
383 href: href,
384 title: title,
385 text: text,
386 tokens: lexer.inlineTokens(text, [])
387 };
388 lexer.state.inLink = false;
389 return token;
390 } else {
391 return {
392 type: 'image',
393 raw: raw,
394 href: href,
395 title: title,
396 text: escape(text)
397 };
398 }
399 }
400
401 function indentCodeCompensation(raw, text) {
402 var matchIndentToCode = raw.match(/^(\s+)(?:```)/);
403
404 if (matchIndentToCode === null) {
405 return text;
406 }
407
408 var indentToCode = matchIndentToCode[1];
409 return text.split('\n').map(function (node) {
410 var matchIndentInNode = node.match(/^\s+/);
411
412 if (matchIndentInNode === null) {
413 return node;
414 }
415
416 var indentInNode = matchIndentInNode[0];
417
418 if (indentInNode.length >= indentToCode.length) {
419 return node.slice(indentToCode.length);
420 }
421
422 return node;
423 }).join('\n');
424 }
425 /**
426 * Tokenizer
427 */
428
429
430 var Tokenizer = /*#__PURE__*/function () {
431 function Tokenizer(options) {
432 this.options = options || exports.defaults;
433 }
434
435 var _proto = Tokenizer.prototype;
436
437 _proto.space = function space(src) {
438 var cap = this.rules.block.newline.exec(src);
439
440 if (cap && cap[0].length > 0) {
441 return {
442 type: 'space',
443 raw: cap[0]
444 };
445 }
446 };
447
448 _proto.code = function code(src) {
449 var cap = this.rules.block.code.exec(src);
450
451 if (cap) {
452 var text = cap[0].replace(/^ {1,4}/gm, '');
453 return {
454 type: 'code',
455 raw: cap[0],
456 codeBlockStyle: 'indented',
457 text: !this.options.pedantic ? rtrim(text, '\n') : text
458 };
459 }
460 };
461
462 _proto.fences = function fences(src) {
463 var cap = this.rules.block.fences.exec(src);
464
465 if (cap) {
466 var raw = cap[0];
467 var text = indentCodeCompensation(raw, cap[3] || '');
468 return {
469 type: 'code',
470 raw: raw,
471 lang: cap[2] ? cap[2].trim() : cap[2],
472 text: text
473 };
474 }
475 };
476
477 _proto.heading = function heading(src) {
478 var cap = this.rules.block.heading.exec(src);
479
480 if (cap) {
481 var text = cap[2].trim(); // remove trailing #s
482
483 if (/#$/.test(text)) {
484 var trimmed = rtrim(text, '#');
485
486 if (this.options.pedantic) {
487 text = trimmed.trim();
488 } else if (!trimmed || / $/.test(trimmed)) {
489 // CommonMark requires space before trailing #s
490 text = trimmed.trim();
491 }
492 }
493
494 var token = {
495 type: 'heading',
496 raw: cap[0],
497 depth: cap[1].length,
498 text: text,
499 tokens: []
500 };
501 this.lexer.inline(token.text, token.tokens);
502 return token;
503 }
504 };
505
506 _proto.hr = function hr(src) {
507 var cap = this.rules.block.hr.exec(src);
508
509 if (cap) {
510 return {
511 type: 'hr',
512 raw: cap[0]
513 };
514 }
515 };
516
517 _proto.blockquote = function blockquote(src) {
518 var cap = this.rules.block.blockquote.exec(src);
519
520 if (cap) {
521 var text = cap[0].replace(/^ *> ?/gm, '');
522 return {
523 type: 'blockquote',
524 raw: cap[0],
525 tokens: this.lexer.blockTokens(text, []),
526 text: text
527 };
528 }
529 };
530
531 _proto.list = function list(src) {
532 var cap = this.rules.block.list.exec(src);
533
534 if (cap) {
535 var raw, istask, ischecked, indent, i, blankLine, endsWithBlankLine, line, nextLine, rawLine, itemContents, endEarly;
536 var bull = cap[1].trim();
537 var isordered = bull.length > 1;
538 var list = {
539 type: 'list',
540 raw: '',
541 ordered: isordered,
542 start: isordered ? +bull.slice(0, -1) : '',
543 loose: false,
544 items: []
545 };
546 bull = isordered ? "\\d{1,9}\\" + bull.slice(-1) : "\\" + bull;
547
548 if (this.options.pedantic) {
549 bull = isordered ? bull : '[*+-]';
550 } // Get next list item
551
552
553 var itemRegex = new RegExp("^( {0,3}" + bull + ")((?: [^\\n]*)?(?:\\n|$))"); // Check if current bullet point can start a new List Item
554
555 while (src) {
556 endEarly = false;
557
558 if (!(cap = itemRegex.exec(src))) {
559 break;
560 }
561
562 if (this.rules.block.hr.test(src)) {
563 // End list if bullet was actually HR (possibly move into itemRegex?)
564 break;
565 }
566
567 raw = cap[0];
568 src = src.substring(raw.length);
569 line = cap[2].split('\n', 1)[0];
570 nextLine = src.split('\n', 1)[0];
571
572 if (this.options.pedantic) {
573 indent = 2;
574 itemContents = line.trimLeft();
575 } else {
576 indent = cap[2].search(/[^ ]/); // Find first non-space char
577
578 indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
579
580 itemContents = line.slice(indent);
581 indent += cap[1].length;
582 }
583
584 blankLine = false;
585
586 if (!line && /^ *$/.test(nextLine)) {
587 // Items begin with at most one blank line
588 raw += nextLine + '\n';
589 src = src.substring(nextLine.length + 1);
590 endEarly = true;
591 }
592
593 if (!endEarly) {
594 var nextBulletRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:[*+-]|\\d{1,9}[.)])"); // Check if following lines should be included in List Item
595
596 while (src) {
597 rawLine = src.split('\n', 1)[0];
598 line = rawLine; // Re-align to follow commonmark nesting rules
599
600 if (this.options.pedantic) {
601 line = line.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
602 } // End list item if found start of new bullet
603
604
605 if (nextBulletRegex.test(line)) {
606 break;
607 }
608
609 if (line.search(/[^ ]/) >= indent || !line.trim()) {
610 // Dedent if possible
611 itemContents += '\n' + line.slice(indent);
612 } else if (!blankLine) {
613 // Until blank line, item doesn't need indentation
614 itemContents += '\n' + line;
615 } else {
616 // Otherwise, improper indentation ends this item
617 break;
618 }
619
620 if (!blankLine && !line.trim()) {
621 // Check if current line is blank
622 blankLine = true;
623 }
624
625 raw += rawLine + '\n';
626 src = src.substring(rawLine.length + 1);
627 }
628 }
629
630 if (!list.loose) {
631 // If the previous item ended with a blank line, the list is loose
632 if (endsWithBlankLine) {
633 list.loose = true;
634 } else if (/\n *\n *$/.test(raw)) {
635 endsWithBlankLine = true;
636 }
637 } // Check for task list items
638
639
640 if (this.options.gfm) {
641 istask = /^\[[ xX]\] /.exec(itemContents);
642
643 if (istask) {
644 ischecked = istask[0] !== '[ ] ';
645 itemContents = itemContents.replace(/^\[[ xX]\] +/, '');
646 }
647 }
648
649 list.items.push({
650 type: 'list_item',
651 raw: raw,
652 task: !!istask,
653 checked: ischecked,
654 loose: false,
655 text: itemContents
656 });
657 list.raw += raw;
658 } // Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
659
660
661 list.items[list.items.length - 1].raw = raw.trimRight();
662 list.items[list.items.length - 1].text = itemContents.trimRight();
663 list.raw = list.raw.trimRight();
664 var l = list.items.length; // Item child tokens handled here at end because we needed to have the final item to trim it first
665
666 for (i = 0; i < l; i++) {
667 this.lexer.state.top = false;
668 list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
669 var spacers = list.items[i].tokens.filter(function (t) {
670 return t.type === 'space';
671 });
672 var hasMultipleLineBreaks = spacers.every(function (t) {
673 var chars = t.raw.split('');
674 var lineBreaks = 0;
675
676 for (var _iterator = _createForOfIteratorHelperLoose(chars), _step; !(_step = _iterator()).done;) {
677 var _char = _step.value;
678
679 if (_char === '\n') {
680 lineBreaks += 1;
681 }
682
683 if (lineBreaks > 1) {
684 return true;
685 }
686 }
687
688 return false;
689 });
690
691 if (!list.loose && spacers.length && hasMultipleLineBreaks) {
692 // Having a single line break doesn't mean a list is loose. A single line break is terminating the last list item
693 list.loose = true;
694 list.items[i].loose = true;
695 }
696 }
697
698 return list;
699 }
700 };
701
702 _proto.html = function html(src) {
703 var cap = this.rules.block.html.exec(src);
704
705 if (cap) {
706 var token = {
707 type: 'html',
708 raw: cap[0],
709 pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
710 text: cap[0]
711 };
712
713 if (this.options.sanitize) {
714 token.type = 'paragraph';
715 token.text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
716 token.tokens = [];
717 this.lexer.inline(token.text, token.tokens);
718 }
719
720 return token;
721 }
722 };
723
724 _proto.def = function def(src) {
725 var cap = this.rules.block.def.exec(src);
726
727 if (cap) {
728 if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
729 var tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
730 return {
731 type: 'def',
732 tag: tag,
733 raw: cap[0],
734 href: cap[2],
735 title: cap[3]
736 };
737 }
738 };
739
740 _proto.table = function table(src) {
741 var cap = this.rules.block.table.exec(src);
742
743 if (cap) {
744 var item = {
745 type: 'table',
746 header: splitCells(cap[1]).map(function (c) {
747 return {
748 text: c
749 };
750 }),
751 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
752 rows: cap[3] ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : []
753 };
754
755 if (item.header.length === item.align.length) {
756 item.raw = cap[0];
757 var l = item.align.length;
758 var i, j, k, row;
759
760 for (i = 0; i < l; i++) {
761 if (/^ *-+: *$/.test(item.align[i])) {
762 item.align[i] = 'right';
763 } else if (/^ *:-+: *$/.test(item.align[i])) {
764 item.align[i] = 'center';
765 } else if (/^ *:-+ *$/.test(item.align[i])) {
766 item.align[i] = 'left';
767 } else {
768 item.align[i] = null;
769 }
770 }
771
772 l = item.rows.length;
773
774 for (i = 0; i < l; i++) {
775 item.rows[i] = splitCells(item.rows[i], item.header.length).map(function (c) {
776 return {
777 text: c
778 };
779 });
780 } // parse child tokens inside headers and cells
781 // header child tokens
782
783
784 l = item.header.length;
785
786 for (j = 0; j < l; j++) {
787 item.header[j].tokens = [];
788 this.lexer.inlineTokens(item.header[j].text, item.header[j].tokens);
789 } // cell child tokens
790
791
792 l = item.rows.length;
793
794 for (j = 0; j < l; j++) {
795 row = item.rows[j];
796
797 for (k = 0; k < row.length; k++) {
798 row[k].tokens = [];
799 this.lexer.inlineTokens(row[k].text, row[k].tokens);
800 }
801 }
802
803 return item;
804 }
805 }
806 };
807
808 _proto.lheading = function lheading(src) {
809 var cap = this.rules.block.lheading.exec(src);
810
811 if (cap) {
812 var token = {
813 type: 'heading',
814 raw: cap[0],
815 depth: cap[2].charAt(0) === '=' ? 1 : 2,
816 text: cap[1],
817 tokens: []
818 };
819 this.lexer.inline(token.text, token.tokens);
820 return token;
821 }
822 };
823
824 _proto.paragraph = function paragraph(src) {
825 var cap = this.rules.block.paragraph.exec(src);
826
827 if (cap) {
828 var token = {
829 type: 'paragraph',
830 raw: cap[0],
831 text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1],
832 tokens: []
833 };
834 this.lexer.inline(token.text, token.tokens);
835 return token;
836 }
837 };
838
839 _proto.text = function text(src) {
840 var cap = this.rules.block.text.exec(src);
841
842 if (cap) {
843 var token = {
844 type: 'text',
845 raw: cap[0],
846 text: cap[0],
847 tokens: []
848 };
849 this.lexer.inline(token.text, token.tokens);
850 return token;
851 }
852 };
853
854 _proto.escape = function escape$1(src) {
855 var cap = this.rules.inline.escape.exec(src);
856
857 if (cap) {
858 return {
859 type: 'escape',
860 raw: cap[0],
861 text: escape(cap[1])
862 };
863 }
864 };
865
866 _proto.tag = function tag(src) {
867 var cap = this.rules.inline.tag.exec(src);
868
869 if (cap) {
870 if (!this.lexer.state.inLink && /^<a /i.test(cap[0])) {
871 this.lexer.state.inLink = true;
872 } else if (this.lexer.state.inLink && /^<\/a>/i.test(cap[0])) {
873 this.lexer.state.inLink = false;
874 }
875
876 if (!this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
877 this.lexer.state.inRawBlock = true;
878 } else if (this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
879 this.lexer.state.inRawBlock = false;
880 }
881
882 return {
883 type: this.options.sanitize ? 'text' : 'html',
884 raw: cap[0],
885 inLink: this.lexer.state.inLink,
886 inRawBlock: this.lexer.state.inRawBlock,
887 text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) : cap[0]
888 };
889 }
890 };
891
892 _proto.link = function link(src) {
893 var cap = this.rules.inline.link.exec(src);
894
895 if (cap) {
896 var trimmedUrl = cap[2].trim();
897
898 if (!this.options.pedantic && /^</.test(trimmedUrl)) {
899 // commonmark requires matching angle brackets
900 if (!/>$/.test(trimmedUrl)) {
901 return;
902 } // ending angle bracket cannot be escaped
903
904
905 var rtrimSlash = rtrim(trimmedUrl.slice(0, -1), '\\');
906
907 if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
908 return;
909 }
910 } else {
911 // find closing parenthesis
912 var lastParenIndex = findClosingBracket(cap[2], '()');
913
914 if (lastParenIndex > -1) {
915 var start = cap[0].indexOf('!') === 0 ? 5 : 4;
916 var linkLen = start + cap[1].length + lastParenIndex;
917 cap[2] = cap[2].substring(0, lastParenIndex);
918 cap[0] = cap[0].substring(0, linkLen).trim();
919 cap[3] = '';
920 }
921 }
922
923 var href = cap[2];
924 var title = '';
925
926 if (this.options.pedantic) {
927 // split pedantic href and title
928 var link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
929
930 if (link) {
931 href = link[1];
932 title = link[3];
933 }
934 } else {
935 title = cap[3] ? cap[3].slice(1, -1) : '';
936 }
937
938 href = href.trim();
939
940 if (/^</.test(href)) {
941 if (this.options.pedantic && !/>$/.test(trimmedUrl)) {
942 // pedantic allows starting angle bracket without ending angle bracket
943 href = href.slice(1);
944 } else {
945 href = href.slice(1, -1);
946 }
947 }
948
949 return outputLink(cap, {
950 href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
951 title: title ? title.replace(this.rules.inline._escapes, '$1') : title
952 }, cap[0], this.lexer);
953 }
954 };
955
956 _proto.reflink = function reflink(src, links) {
957 var cap;
958
959 if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
960 var link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
961 link = links[link.toLowerCase()];
962
963 if (!link || !link.href) {
964 var text = cap[0].charAt(0);
965 return {
966 type: 'text',
967 raw: text,
968 text: text
969 };
970 }
971
972 return outputLink(cap, link, cap[0], this.lexer);
973 }
974 };
975
976 _proto.emStrong = function emStrong(src, maskedSrc, prevChar) {
977 if (prevChar === void 0) {
978 prevChar = '';
979 }
980
981 var match = this.rules.inline.emStrong.lDelim.exec(src);
982 if (!match) return; // _ can't be between two alphanumerics. \p{L}\p{N} includes non-english alphabet/numbers as well
983
984 if (match[3] && prevChar.match(/(?:[0-9A-Za-z\xAA\xB2\xB3\xB5\xB9\xBA\xBC-\xBE\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u0660-\u0669\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07C0-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0966-\u096F\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09E6-\u09F1\u09F4-\u09F9\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A66-\u0A6F\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AE6-\u0AEF\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B66-\u0B6F\u0B71-\u0B77\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0BE6-\u0BF2\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C66-\u0C6F\u0C78-\u0C7E\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CE6-\u0CEF\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D58-\u0D61\u0D66-\u0D78\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DE6-\u0DEF\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F20-\u0F33\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F-\u1049\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u1090-\u1099\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1369-\u137C\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u17E0-\u17E9\u17F0-\u17F9\u1810-\u1819\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A16\u1A20-\u1A54\u1A80-\u1A89\u1A90-\u1A99\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B50-\u1B59\u1B83-\u1BA0\u1BAE-\u1BE5\u1C00-\u1C23\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2070\u2071\u2074-\u2079\u207F-\u2089\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u2460-\u249B\u24EA-\u24FF\u2776-\u2793\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2CFD\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u3192-\u3195\u31A0-\u31BF\u31F0-\u31FF\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA830-\uA835\uA840-\uA873\uA882-\uA8B3\uA8D0-\uA8D9\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA900-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF-\uA9D9\uA9E0-\uA9E4\uA9E6-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA50-\uAA59\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD07-\uDD33\uDD40-\uDD78\uDD8A\uDD8B\uDE80-\uDE9C\uDEA0-\uDED0\uDEE1-\uDEFB\uDF00-\uDF23\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC58-\uDC76\uDC79-\uDC9E\uDCA7-\uDCAF\uDCE0-\uDCF2\uDCF4\uDCF5\uDCFB-\uDD1B\uDD20-\uDD39\uDD80-\uDDB7\uDDBC-\uDDCF\uDDD2-\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE40-\uDE48\uDE60-\uDE7E\uDE80-\uDE9F\uDEC0-\uDEC7\uDEC9-\uDEE4\uDEEB-\uDEEF\uDF00-\uDF35\uDF40-\uDF55\uDF58-\uDF72\uDF78-\uDF91\uDFA9-\uDFAF]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDCFA-\uDD23\uDD30-\uDD39\uDE60-\uDE7E\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF27\uDF30-\uDF45\uDF51-\uDF54\uDF70-\uDF81\uDFB0-\uDFCB\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC52-\uDC6F\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD03-\uDD26\uDD36-\uDD3F\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDD0-\uDDDA\uDDDC\uDDE1-\uDDF4\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDEF0-\uDEF9\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC50-\uDC59\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE50-\uDE59\uDE80-\uDEAA\uDEB8\uDEC0-\uDEC9\uDF00-\uDF1A\uDF30-\uDF3B\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCF2\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDD50-\uDD59\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC50-\uDC6C\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD50-\uDD59\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDDA0-\uDDA9\uDEE0-\uDEF2\uDFB0\uDFC0-\uDFD4]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDE70-\uDEBE\uDEC0-\uDEC9\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF50-\uDF59\uDF5B-\uDF61\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE96\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD50-\uDD52\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD834[\uDEE0-\uDEF3\uDF60-\uDF78]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD837[\uDF00-\uDF1E]|\uD838[\uDD00-\uDD2C\uDD37-\uDD3D\uDD40-\uDD49\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB\uDEF0-\uDEF9]|\uD839[\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDCC7-\uDCCF\uDD00-\uDD43\uDD4B\uDD50-\uDD59]|\uD83B[\uDC71-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDCB4\uDD01-\uDD2D\uDD2F-\uDD3D\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD83C[\uDD00-\uDD0C]|\uD83E[\uDFF0-\uDFF9]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF38\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A])/)) return;
985 var nextChar = match[1] || match[2] || '';
986
987 if (!nextChar || nextChar && (prevChar === '' || this.rules.inline.punctuation.exec(prevChar))) {
988 var lLength = match[0].length - 1;
989 var rDelim,
990 rLength,
991 delimTotal = lLength,
992 midDelimTotal = 0;
993 var endReg = match[0][0] === '*' ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
994 endReg.lastIndex = 0; // Clip maskedSrc to same section of string as src (move to lexer?)
995
996 maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
997
998 while ((match = endReg.exec(maskedSrc)) != null) {
999 rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
1000 if (!rDelim) continue; // skip single * in __abc*abc__
1001
1002 rLength = rDelim.length;
1003
1004 if (match[3] || match[4]) {
1005 // found another Left Delim
1006 delimTotal += rLength;
1007 continue;
1008 } else if (match[5] || match[6]) {
1009 // either Left or Right Delim
1010 if (lLength % 3 && !((lLength + rLength) % 3)) {
1011 midDelimTotal += rLength;
1012 continue; // CommonMark Emphasis Rules 9-10
1013 }
1014 }
1015
1016 delimTotal -= rLength;
1017 if (delimTotal > 0) continue; // Haven't found enough closing delimiters
1018 // Remove extra characters. *a*** -> *a*
1019
1020 rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal); // Create `em` if smallest delimiter has odd char count. *a***
1021
1022 if (Math.min(lLength, rLength) % 2) {
1023 var _text = src.slice(1, lLength + match.index + rLength);
1024
1025 return {
1026 type: 'em',
1027 raw: src.slice(0, lLength + match.index + rLength + 1),
1028 text: _text,
1029 tokens: this.lexer.inlineTokens(_text, [])
1030 };
1031 } // Create 'strong' if smallest delimiter has even char count. **a***
1032
1033
1034 var text = src.slice(2, lLength + match.index + rLength - 1);
1035 return {
1036 type: 'strong',
1037 raw: src.slice(0, lLength + match.index + rLength + 1),
1038 text: text,
1039 tokens: this.lexer.inlineTokens(text, [])
1040 };
1041 }
1042 }
1043 };
1044
1045 _proto.codespan = function codespan(src) {
1046 var cap = this.rules.inline.code.exec(src);
1047
1048 if (cap) {
1049 var text = cap[2].replace(/\n/g, ' ');
1050 var hasNonSpaceChars = /[^ ]/.test(text);
1051 var hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
1052
1053 if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
1054 text = text.substring(1, text.length - 1);
1055 }
1056
1057 text = escape(text, true);
1058 return {
1059 type: 'codespan',
1060 raw: cap[0],
1061 text: text
1062 };
1063 }
1064 };
1065
1066 _proto.br = function br(src) {
1067 var cap = this.rules.inline.br.exec(src);
1068
1069 if (cap) {
1070 return {
1071 type: 'br',
1072 raw: cap[0]
1073 };
1074 }
1075 };
1076
1077 _proto.del = function del(src) {
1078 var cap = this.rules.inline.del.exec(src);
1079
1080 if (cap) {
1081 return {
1082 type: 'del',
1083 raw: cap[0],
1084 text: cap[2],
1085 tokens: this.lexer.inlineTokens(cap[2], [])
1086 };
1087 }
1088 };
1089
1090 _proto.autolink = function autolink(src, mangle) {
1091 var cap = this.rules.inline.autolink.exec(src);
1092
1093 if (cap) {
1094 var text, href;
1095
1096 if (cap[2] === '@') {
1097 text = escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
1098 href = 'mailto:' + text;
1099 } else {
1100 text = escape(cap[1]);
1101 href = text;
1102 }
1103
1104 return {
1105 type: 'link',
1106 raw: cap[0],
1107 text: text,
1108 href: href,
1109 tokens: [{
1110 type: 'text',
1111 raw: text,
1112 text: text
1113 }]
1114 };
1115 }
1116 };
1117
1118 _proto.url = function url(src, mangle) {
1119 var cap;
1120
1121 if (cap = this.rules.inline.url.exec(src)) {
1122 var text, href;
1123
1124 if (cap[2] === '@') {
1125 text = escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
1126 href = 'mailto:' + text;
1127 } else {
1128 // do extended autolink path validation
1129 var prevCapZero;
1130
1131 do {
1132 prevCapZero = cap[0];
1133 cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
1134 } while (prevCapZero !== cap[0]);
1135
1136 text = escape(cap[0]);
1137
1138 if (cap[1] === 'www.') {
1139 href = 'http://' + text;
1140 } else {
1141 href = text;
1142 }
1143 }
1144
1145 return {
1146 type: 'link',
1147 raw: cap[0],
1148 text: text,
1149 href: href,
1150 tokens: [{
1151 type: 'text',
1152 raw: text,
1153 text: text
1154 }]
1155 };
1156 }
1157 };
1158
1159 _proto.inlineText = function inlineText(src, smartypants) {
1160 var cap = this.rules.inline.text.exec(src);
1161
1162 if (cap) {
1163 var text;
1164
1165 if (this.lexer.state.inRawBlock) {
1166 text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) : cap[0];
1167 } else {
1168 text = escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
1169 }
1170
1171 return {
1172 type: 'text',
1173 raw: cap[0],
1174 text: text
1175 };
1176 }
1177 };
1178
1179 return Tokenizer;
1180 }();
1181
1182 /**
1183 * Block-Level Grammar
1184 */
1185
1186 var block = {
1187 newline: /^(?: *(?:\n|$))+/,
1188 code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
1189 fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
1190 hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
1191 heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
1192 blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
1193 list: /^( {0,3}bull)( [^\n]+?)?(?:\n|$)/,
1194 html: '^ {0,3}(?:' // optional indentation
1195 + '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
1196 + '|comment[^\\n]*(\\n+|$)' // (2)
1197 + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
1198 + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
1199 + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
1200 + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (6)
1201 + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
1202 + '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
1203 + ')',
1204 def: /^ {0,3}\[(label)\]: *(?:\n *)?<?([^\s>]+)>?(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
1205 table: noopTest,
1206 lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
1207 // regex template, placeholders will be replaced according to different paragraph
1208 // interruption rules of commonmark and the original markdown spec:
1209 _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
1210 text: /^[^\n]+/
1211 };
1212 block._label = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
1213 block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
1214 block.def = edit(block.def).replace('label', block._label).replace('title', block._title).getRegex();
1215 block.bullet = /(?:[*+-]|\d{1,9}[.)])/;
1216 block.listItemStart = edit(/^( *)(bull) */).replace('bull', block.bullet).getRegex();
1217 block.list = edit(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex();
1218 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';
1219 block._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;
1220 block.html = edit(block.html, 'i').replace('comment', block._comment).replace('tag', block._tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
1221 block.paragraph = edit(block._paragraph).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} ').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
1222 .replace('|table', '').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
1223 .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
1224 .getRegex();
1225 block.blockquote = edit(block.blockquote).replace('paragraph', block.paragraph).getRegex();
1226 /**
1227 * Normal Block Grammar
1228 */
1229
1230 block.normal = merge({}, block);
1231 /**
1232 * GFM Block Grammar
1233 */
1234
1235 block.gfm = merge({}, block.normal, {
1236 table: '^ *([^\\n ].*\\|.*)\\n' // Header
1237 + ' {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?' // Align
1238 + '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
1239
1240 });
1241 block.gfm.table = edit(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
1242 .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
1243 .getRegex();
1244 block.gfm.paragraph = edit(block._paragraph).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} ').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
1245 .replace('table', block.gfm.table) // interrupt paragraphs with table
1246 .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
1247 .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
1248 .getRegex();
1249 /**
1250 * Pedantic grammar (original John Gruber's loose markdown specification)
1251 */
1252
1253 block.pedantic = merge({}, block.normal, {
1254 html: edit('^ *(?:comment *(?:\\n|\\s*$)' + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
1255 + '|<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(),
1256 def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
1257 heading: /^(#{1,6})(.*)(?:\n+|$)/,
1258 fences: noopTest,
1259 // fences not supported
1260 paragraph: edit(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()
1261 });
1262 /**
1263 * Inline-Level Grammar
1264 */
1265
1266 var inline = {
1267 escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
1268 autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
1269 url: noopTest,
1270 tag: '^comment' + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
1271 + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
1272 + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
1273 + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
1274 + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>',
1275 // CDATA section
1276 link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
1277 reflink: /^!?\[(label)\]\[(ref)\]/,
1278 nolink: /^!?\[(ref)\](?:\[\])?/,
1279 reflinkSearch: 'reflink|nolink(?!\\()',
1280 emStrong: {
1281 lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
1282 // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
1283 // () Skip orphan delim inside strong (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
1284 rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
1285 rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
1286
1287 },
1288 code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
1289 br: /^( {2,}|\\)\n(?!\s*$)/,
1290 del: noopTest,
1291 text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
1292 punctuation: /^([\spunctuation])/
1293 }; // list of punctuation marks from CommonMark spec
1294 // without * and _ to handle the different emphasis markers * and _
1295
1296 inline._punctuation = '!"#$%&\'()+\\-.,/:;<=>?@\\[\\]`^{|}~';
1297 inline.punctuation = edit(inline.punctuation).replace(/punctuation/g, inline._punctuation).getRegex(); // sequences em should skip over [title](link), `code`, <html>
1298
1299 inline.blockSkip = /\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;
1300 inline.escapedEmSt = /\\\*|\\_/g;
1301 inline._comment = edit(block._comment).replace('(?:-->|$)', '-->').getRegex();
1302 inline.emStrong.lDelim = edit(inline.emStrong.lDelim).replace(/punct/g, inline._punctuation).getRegex();
1303 inline.emStrong.rDelimAst = edit(inline.emStrong.rDelimAst, 'g').replace(/punct/g, inline._punctuation).getRegex();
1304 inline.emStrong.rDelimUnd = edit(inline.emStrong.rDelimUnd, 'g').replace(/punct/g, inline._punctuation).getRegex();
1305 inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
1306 inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
1307 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])?)+(?![-_])/;
1308 inline.autolink = edit(inline.autolink).replace('scheme', inline._scheme).replace('email', inline._email).getRegex();
1309 inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
1310 inline.tag = edit(inline.tag).replace('comment', inline._comment).replace('attribute', inline._attribute).getRegex();
1311 inline._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
1312 inline._href = /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/;
1313 inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
1314 inline.link = edit(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex();
1315 inline.reflink = edit(inline.reflink).replace('label', inline._label).replace('ref', block._label).getRegex();
1316 inline.nolink = edit(inline.nolink).replace('ref', block._label).getRegex();
1317 inline.reflinkSearch = edit(inline.reflinkSearch, 'g').replace('reflink', inline.reflink).replace('nolink', inline.nolink).getRegex();
1318 /**
1319 * Normal Inline Grammar
1320 */
1321
1322 inline.normal = merge({}, inline);
1323 /**
1324 * Pedantic Inline Grammar
1325 */
1326
1327 inline.pedantic = merge({}, inline.normal, {
1328 strong: {
1329 start: /^__|\*\*/,
1330 middle: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
1331 endAst: /\*\*(?!\*)/g,
1332 endUnd: /__(?!_)/g
1333 },
1334 em: {
1335 start: /^_|\*/,
1336 middle: /^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,
1337 endAst: /\*(?!\*)/g,
1338 endUnd: /_(?!_)/g
1339 },
1340 link: edit(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(),
1341 reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex()
1342 });
1343 /**
1344 * GFM Inline Grammar
1345 */
1346
1347 inline.gfm = merge({}, inline.normal, {
1348 escape: edit(inline.escape).replace('])', '~|])').getRegex(),
1349 _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
1350 url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
1351 _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
1352 del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
1353 text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
1354 });
1355 inline.gfm.url = edit(inline.gfm.url, 'i').replace('email', inline.gfm._extended_email).getRegex();
1356 /**
1357 * GFM + Line Breaks Inline Grammar
1358 */
1359
1360 inline.breaks = merge({}, inline.gfm, {
1361 br: edit(inline.br).replace('{2,}', '*').getRegex(),
1362 text: edit(inline.gfm.text).replace('\\b_', '\\b_| {2,}\\n').replace(/\{2,\}/g, '*').getRegex()
1363 });
1364
1365 /**
1366 * smartypants text replacement
1367 */
1368
1369 function smartypants(text) {
1370 return text // em-dashes
1371 .replace(/---/g, "\u2014") // en-dashes
1372 .replace(/--/g, "\u2013") // opening singles
1373 .replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // closing singles & apostrophes
1374 .replace(/'/g, "\u2019") // opening doubles
1375 .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C") // closing doubles
1376 .replace(/"/g, "\u201D") // ellipses
1377 .replace(/\.{3}/g, "\u2026");
1378 }
1379 /**
1380 * mangle email addresses
1381 */
1382
1383
1384 function mangle(text) {
1385 var out = '',
1386 i,
1387 ch;
1388 var l = text.length;
1389
1390 for (i = 0; i < l; i++) {
1391 ch = text.charCodeAt(i);
1392
1393 if (Math.random() > 0.5) {
1394 ch = 'x' + ch.toString(16);
1395 }
1396
1397 out += '&#' + ch + ';';
1398 }
1399
1400 return out;
1401 }
1402 /**
1403 * Block Lexer
1404 */
1405
1406
1407 var Lexer = /*#__PURE__*/function () {
1408 function Lexer(options) {
1409 this.tokens = [];
1410 this.tokens.links = Object.create(null);
1411 this.options = options || exports.defaults;
1412 this.options.tokenizer = this.options.tokenizer || new Tokenizer();
1413 this.tokenizer = this.options.tokenizer;
1414 this.tokenizer.options = this.options;
1415 this.tokenizer.lexer = this;
1416 this.inlineQueue = [];
1417 this.state = {
1418 inLink: false,
1419 inRawBlock: false,
1420 top: true
1421 };
1422 var rules = {
1423 block: block.normal,
1424 inline: inline.normal
1425 };
1426
1427 if (this.options.pedantic) {
1428 rules.block = block.pedantic;
1429 rules.inline = inline.pedantic;
1430 } else if (this.options.gfm) {
1431 rules.block = block.gfm;
1432
1433 if (this.options.breaks) {
1434 rules.inline = inline.breaks;
1435 } else {
1436 rules.inline = inline.gfm;
1437 }
1438 }
1439
1440 this.tokenizer.rules = rules;
1441 }
1442 /**
1443 * Expose Rules
1444 */
1445
1446
1447 /**
1448 * Static Lex Method
1449 */
1450 Lexer.lex = function lex(src, options) {
1451 var lexer = new Lexer(options);
1452 return lexer.lex(src);
1453 }
1454 /**
1455 * Static Lex Inline Method
1456 */
1457 ;
1458
1459 Lexer.lexInline = function lexInline(src, options) {
1460 var lexer = new Lexer(options);
1461 return lexer.inlineTokens(src);
1462 }
1463 /**
1464 * Preprocessing
1465 */
1466 ;
1467
1468 var _proto = Lexer.prototype;
1469
1470 _proto.lex = function lex(src) {
1471 src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ');
1472 this.blockTokens(src, this.tokens);
1473 var next;
1474
1475 while (next = this.inlineQueue.shift()) {
1476 this.inlineTokens(next.src, next.tokens);
1477 }
1478
1479 return this.tokens;
1480 }
1481 /**
1482 * Lexing
1483 */
1484 ;
1485
1486 _proto.blockTokens = function blockTokens(src, tokens) {
1487 var _this = this;
1488
1489 if (tokens === void 0) {
1490 tokens = [];
1491 }
1492
1493 if (this.options.pedantic) {
1494 src = src.replace(/^ +$/gm, '');
1495 }
1496
1497 var token, lastToken, cutSrc, lastParagraphClipped;
1498
1499 while (src) {
1500 if (this.options.extensions && this.options.extensions.block && this.options.extensions.block.some(function (extTokenizer) {
1501 if (token = extTokenizer.call({
1502 lexer: _this
1503 }, src, tokens)) {
1504 src = src.substring(token.raw.length);
1505 tokens.push(token);
1506 return true;
1507 }
1508
1509 return false;
1510 })) {
1511 continue;
1512 } // newline
1513
1514
1515 if (token = this.tokenizer.space(src)) {
1516 src = src.substring(token.raw.length);
1517
1518 if (token.raw.length === 1 && tokens.length > 0) {
1519 // if there's a single \n as a spacer, it's terminating the last line,
1520 // so move it there so that we don't get unecessary paragraph tags
1521 tokens[tokens.length - 1].raw += '\n';
1522 } else {
1523 tokens.push(token);
1524 }
1525
1526 continue;
1527 } // code
1528
1529
1530 if (token = this.tokenizer.code(src)) {
1531 src = src.substring(token.raw.length);
1532 lastToken = tokens[tokens.length - 1]; // An indented code block cannot interrupt a paragraph.
1533
1534 if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1535 lastToken.raw += '\n' + token.raw;
1536 lastToken.text += '\n' + token.text;
1537 this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1538 } else {
1539 tokens.push(token);
1540 }
1541
1542 continue;
1543 } // fences
1544
1545
1546 if (token = this.tokenizer.fences(src)) {
1547 src = src.substring(token.raw.length);
1548 tokens.push(token);
1549 continue;
1550 } // heading
1551
1552
1553 if (token = this.tokenizer.heading(src)) {
1554 src = src.substring(token.raw.length);
1555 tokens.push(token);
1556 continue;
1557 } // hr
1558
1559
1560 if (token = this.tokenizer.hr(src)) {
1561 src = src.substring(token.raw.length);
1562 tokens.push(token);
1563 continue;
1564 } // blockquote
1565
1566
1567 if (token = this.tokenizer.blockquote(src)) {
1568 src = src.substring(token.raw.length);
1569 tokens.push(token);
1570 continue;
1571 } // list
1572
1573
1574 if (token = this.tokenizer.list(src)) {
1575 src = src.substring(token.raw.length);
1576 tokens.push(token);
1577 continue;
1578 } // html
1579
1580
1581 if (token = this.tokenizer.html(src)) {
1582 src = src.substring(token.raw.length);
1583 tokens.push(token);
1584 continue;
1585 } // def
1586
1587
1588 if (token = this.tokenizer.def(src)) {
1589 src = src.substring(token.raw.length);
1590 lastToken = tokens[tokens.length - 1];
1591
1592 if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1593 lastToken.raw += '\n' + token.raw;
1594 lastToken.text += '\n' + token.raw;
1595 this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1596 } else if (!this.tokens.links[token.tag]) {
1597 this.tokens.links[token.tag] = {
1598 href: token.href,
1599 title: token.title
1600 };
1601 }
1602
1603 continue;
1604 } // table (gfm)
1605
1606
1607 if (token = this.tokenizer.table(src)) {
1608 src = src.substring(token.raw.length);
1609 tokens.push(token);
1610 continue;
1611 } // lheading
1612
1613
1614 if (token = this.tokenizer.lheading(src)) {
1615 src = src.substring(token.raw.length);
1616 tokens.push(token);
1617 continue;
1618 } // top-level paragraph
1619 // prevent paragraph consuming extensions by clipping 'src' to extension start
1620
1621
1622 cutSrc = src;
1623
1624 if (this.options.extensions && this.options.extensions.startBlock) {
1625 (function () {
1626 var startIndex = Infinity;
1627 var tempSrc = src.slice(1);
1628 var tempStart = void 0;
1629
1630 _this.options.extensions.startBlock.forEach(function (getStartIndex) {
1631 tempStart = getStartIndex.call({
1632 lexer: this
1633 }, tempSrc);
1634
1635 if (typeof tempStart === 'number' && tempStart >= 0) {
1636 startIndex = Math.min(startIndex, tempStart);
1637 }
1638 });
1639
1640 if (startIndex < Infinity && startIndex >= 0) {
1641 cutSrc = src.substring(0, startIndex + 1);
1642 }
1643 })();
1644 }
1645
1646 if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
1647 lastToken = tokens[tokens.length - 1];
1648
1649 if (lastParagraphClipped && lastToken.type === 'paragraph') {
1650 lastToken.raw += '\n' + token.raw;
1651 lastToken.text += '\n' + token.text;
1652 this.inlineQueue.pop();
1653 this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1654 } else {
1655 tokens.push(token);
1656 }
1657
1658 lastParagraphClipped = cutSrc.length !== src.length;
1659 src = src.substring(token.raw.length);
1660 continue;
1661 } // text
1662
1663
1664 if (token = this.tokenizer.text(src)) {
1665 src = src.substring(token.raw.length);
1666 lastToken = tokens[tokens.length - 1];
1667
1668 if (lastToken && lastToken.type === 'text') {
1669 lastToken.raw += '\n' + token.raw;
1670 lastToken.text += '\n' + token.text;
1671 this.inlineQueue.pop();
1672 this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1673 } else {
1674 tokens.push(token);
1675 }
1676
1677 continue;
1678 }
1679
1680 if (src) {
1681 var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1682
1683 if (this.options.silent) {
1684 console.error(errMsg);
1685 break;
1686 } else {
1687 throw new Error(errMsg);
1688 }
1689 }
1690 }
1691
1692 this.state.top = true;
1693 return tokens;
1694 };
1695
1696 _proto.inline = function inline(src, tokens) {
1697 this.inlineQueue.push({
1698 src: src,
1699 tokens: tokens
1700 });
1701 }
1702 /**
1703 * Lexing/Compiling
1704 */
1705 ;
1706
1707 _proto.inlineTokens = function inlineTokens(src, tokens) {
1708 var _this2 = this;
1709
1710 if (tokens === void 0) {
1711 tokens = [];
1712 }
1713
1714 var token, lastToken, cutSrc; // String with links masked to avoid interference with em and strong
1715
1716 var maskedSrc = src;
1717 var match;
1718 var keepPrevChar, prevChar; // Mask out reflinks
1719
1720 if (this.tokens.links) {
1721 var links = Object.keys(this.tokens.links);
1722
1723 if (links.length > 0) {
1724 while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
1725 if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
1726 maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
1727 }
1728 }
1729 }
1730 } // Mask out other blocks
1731
1732
1733 while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
1734 maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1735 } // Mask out escaped em & strong delimiters
1736
1737
1738 while ((match = this.tokenizer.rules.inline.escapedEmSt.exec(maskedSrc)) != null) {
1739 maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex);
1740 }
1741
1742 while (src) {
1743 if (!keepPrevChar) {
1744 prevChar = '';
1745 }
1746
1747 keepPrevChar = false; // extensions
1748
1749 if (this.options.extensions && this.options.extensions.inline && this.options.extensions.inline.some(function (extTokenizer) {
1750 if (token = extTokenizer.call({
1751 lexer: _this2
1752 }, src, tokens)) {
1753 src = src.substring(token.raw.length);
1754 tokens.push(token);
1755 return true;
1756 }
1757
1758 return false;
1759 })) {
1760 continue;
1761 } // escape
1762
1763
1764 if (token = this.tokenizer.escape(src)) {
1765 src = src.substring(token.raw.length);
1766 tokens.push(token);
1767 continue;
1768 } // tag
1769
1770
1771 if (token = this.tokenizer.tag(src)) {
1772 src = src.substring(token.raw.length);
1773 lastToken = tokens[tokens.length - 1];
1774
1775 if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1776 lastToken.raw += token.raw;
1777 lastToken.text += token.text;
1778 } else {
1779 tokens.push(token);
1780 }
1781
1782 continue;
1783 } // link
1784
1785
1786 if (token = this.tokenizer.link(src)) {
1787 src = src.substring(token.raw.length);
1788 tokens.push(token);
1789 continue;
1790 } // reflink, nolink
1791
1792
1793 if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1794 src = src.substring(token.raw.length);
1795 lastToken = tokens[tokens.length - 1];
1796
1797 if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1798 lastToken.raw += token.raw;
1799 lastToken.text += token.text;
1800 } else {
1801 tokens.push(token);
1802 }
1803
1804 continue;
1805 } // em & strong
1806
1807
1808 if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
1809 src = src.substring(token.raw.length);
1810 tokens.push(token);
1811 continue;
1812 } // code
1813
1814
1815 if (token = this.tokenizer.codespan(src)) {
1816 src = src.substring(token.raw.length);
1817 tokens.push(token);
1818 continue;
1819 } // br
1820
1821
1822 if (token = this.tokenizer.br(src)) {
1823 src = src.substring(token.raw.length);
1824 tokens.push(token);
1825 continue;
1826 } // del (gfm)
1827
1828
1829 if (token = this.tokenizer.del(src)) {
1830 src = src.substring(token.raw.length);
1831 tokens.push(token);
1832 continue;
1833 } // autolink
1834
1835
1836 if (token = this.tokenizer.autolink(src, mangle)) {
1837 src = src.substring(token.raw.length);
1838 tokens.push(token);
1839 continue;
1840 } // url (gfm)
1841
1842
1843 if (!this.state.inLink && (token = this.tokenizer.url(src, mangle))) {
1844 src = src.substring(token.raw.length);
1845 tokens.push(token);
1846 continue;
1847 } // text
1848 // prevent inlineText consuming extensions by clipping 'src' to extension start
1849
1850
1851 cutSrc = src;
1852
1853 if (this.options.extensions && this.options.extensions.startInline) {
1854 (function () {
1855 var startIndex = Infinity;
1856 var tempSrc = src.slice(1);
1857 var tempStart = void 0;
1858
1859 _this2.options.extensions.startInline.forEach(function (getStartIndex) {
1860 tempStart = getStartIndex.call({
1861 lexer: this
1862 }, tempSrc);
1863
1864 if (typeof tempStart === 'number' && tempStart >= 0) {
1865 startIndex = Math.min(startIndex, tempStart);
1866 }
1867 });
1868
1869 if (startIndex < Infinity && startIndex >= 0) {
1870 cutSrc = src.substring(0, startIndex + 1);
1871 }
1872 })();
1873 }
1874
1875 if (token = this.tokenizer.inlineText(cutSrc, smartypants)) {
1876 src = src.substring(token.raw.length);
1877
1878 if (token.raw.slice(-1) !== '_') {
1879 // Track prevChar before string of ____ started
1880 prevChar = token.raw.slice(-1);
1881 }
1882
1883 keepPrevChar = true;
1884 lastToken = tokens[tokens.length - 1];
1885
1886 if (lastToken && lastToken.type === 'text') {
1887 lastToken.raw += token.raw;
1888 lastToken.text += token.text;
1889 } else {
1890 tokens.push(token);
1891 }
1892
1893 continue;
1894 }
1895
1896 if (src) {
1897 var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1898
1899 if (this.options.silent) {
1900 console.error(errMsg);
1901 break;
1902 } else {
1903 throw new Error(errMsg);
1904 }
1905 }
1906 }
1907
1908 return tokens;
1909 };
1910
1911 _createClass(Lexer, null, [{
1912 key: "rules",
1913 get: function get() {
1914 return {
1915 block: block,
1916 inline: inline
1917 };
1918 }
1919 }]);
1920
1921 return Lexer;
1922 }();
1923
1924 /**
1925 * Renderer
1926 */
1927
1928 var Renderer = /*#__PURE__*/function () {
1929 function Renderer(options) {
1930 this.options = options || exports.defaults;
1931 }
1932
1933 var _proto = Renderer.prototype;
1934
1935 _proto.code = function code(_code, infostring, escaped) {
1936 var lang = (infostring || '').match(/\S*/)[0];
1937
1938 if (this.options.highlight) {
1939 var out = this.options.highlight(_code, lang);
1940
1941 if (out != null && out !== _code) {
1942 escaped = true;
1943 _code = out;
1944 }
1945 }
1946
1947 _code = _code.replace(/\n$/, '') + '\n';
1948
1949 if (!lang) {
1950 return '<pre><code>' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
1951 }
1952
1953 return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
1954 };
1955
1956 _proto.blockquote = function blockquote(quote) {
1957 return '<blockquote>\n' + quote + '</blockquote>\n';
1958 };
1959
1960 _proto.html = function html(_html) {
1961 return _html;
1962 };
1963
1964 _proto.heading = function heading(text, level, raw, slugger) {
1965 if (this.options.headerIds) {
1966 return '<h' + level + ' id="' + this.options.headerPrefix + slugger.slug(raw) + '">' + text + '</h' + level + '>\n';
1967 } // ignore IDs
1968
1969
1970 return '<h' + level + '>' + text + '</h' + level + '>\n';
1971 };
1972
1973 _proto.hr = function hr() {
1974 return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
1975 };
1976
1977 _proto.list = function list(body, ordered, start) {
1978 var type = ordered ? 'ol' : 'ul',
1979 startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
1980 return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
1981 };
1982
1983 _proto.listitem = function listitem(text) {
1984 return '<li>' + text + '</li>\n';
1985 };
1986
1987 _proto.checkbox = function checkbox(checked) {
1988 return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
1989 };
1990
1991 _proto.paragraph = function paragraph(text) {
1992 return '<p>' + text + '</p>\n';
1993 };
1994
1995 _proto.table = function table(header, body) {
1996 if (body) body = '<tbody>' + body + '</tbody>';
1997 return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
1998 };
1999
2000 _proto.tablerow = function tablerow(content) {
2001 return '<tr>\n' + content + '</tr>\n';
2002 };
2003
2004 _proto.tablecell = function tablecell(content, flags) {
2005 var type = flags.header ? 'th' : 'td';
2006 var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>';
2007 return tag + content + '</' + type + '>\n';
2008 } // span level renderer
2009 ;
2010
2011 _proto.strong = function strong(text) {
2012 return '<strong>' + text + '</strong>';
2013 };
2014
2015 _proto.em = function em(text) {
2016 return '<em>' + text + '</em>';
2017 };
2018
2019 _proto.codespan = function codespan(text) {
2020 return '<code>' + text + '</code>';
2021 };
2022
2023 _proto.br = function br() {
2024 return this.options.xhtml ? '<br/>' : '<br>';
2025 };
2026
2027 _proto.del = function del(text) {
2028 return '<del>' + text + '</del>';
2029 };
2030
2031 _proto.link = function link(href, title, text) {
2032 href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
2033
2034 if (href === null) {
2035 return text;
2036 }
2037
2038 var out = '<a href="' + escape(href) + '"';
2039
2040 if (title) {
2041 out += ' title="' + title + '"';
2042 }
2043
2044 out += '>' + text + '</a>';
2045 return out;
2046 };
2047
2048 _proto.image = function image(href, title, text) {
2049 href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
2050
2051 if (href === null) {
2052 return text;
2053 }
2054
2055 var out = '<img src="' + href + '" alt="' + text + '"';
2056
2057 if (title) {
2058 out += ' title="' + title + '"';
2059 }
2060
2061 out += this.options.xhtml ? '/>' : '>';
2062 return out;
2063 };
2064
2065 _proto.text = function text(_text) {
2066 return _text;
2067 };
2068
2069 return Renderer;
2070 }();
2071
2072 /**
2073 * TextRenderer
2074 * returns only the textual part of the token
2075 */
2076 var TextRenderer = /*#__PURE__*/function () {
2077 function TextRenderer() {}
2078
2079 var _proto = TextRenderer.prototype;
2080
2081 // no need for block level renderers
2082 _proto.strong = function strong(text) {
2083 return text;
2084 };
2085
2086 _proto.em = function em(text) {
2087 return text;
2088 };
2089
2090 _proto.codespan = function codespan(text) {
2091 return text;
2092 };
2093
2094 _proto.del = function del(text) {
2095 return text;
2096 };
2097
2098 _proto.html = function html(text) {
2099 return text;
2100 };
2101
2102 _proto.text = function text(_text) {
2103 return _text;
2104 };
2105
2106 _proto.link = function link(href, title, text) {
2107 return '' + text;
2108 };
2109
2110 _proto.image = function image(href, title, text) {
2111 return '' + text;
2112 };
2113
2114 _proto.br = function br() {
2115 return '';
2116 };
2117
2118 return TextRenderer;
2119 }();
2120
2121 /**
2122 * Slugger generates header id
2123 */
2124 var Slugger = /*#__PURE__*/function () {
2125 function Slugger() {
2126 this.seen = {};
2127 }
2128
2129 var _proto = Slugger.prototype;
2130
2131 _proto.serialize = function serialize(value) {
2132 return value.toLowerCase().trim() // remove html tags
2133 .replace(/<[!\/a-z].*?>/ig, '') // remove unwanted chars
2134 .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
2135 }
2136 /**
2137 * Finds the next safe (unique) slug to use
2138 */
2139 ;
2140
2141 _proto.getNextSafeSlug = function getNextSafeSlug(originalSlug, isDryRun) {
2142 var slug = originalSlug;
2143 var occurenceAccumulator = 0;
2144
2145 if (this.seen.hasOwnProperty(slug)) {
2146 occurenceAccumulator = this.seen[originalSlug];
2147
2148 do {
2149 occurenceAccumulator++;
2150 slug = originalSlug + '-' + occurenceAccumulator;
2151 } while (this.seen.hasOwnProperty(slug));
2152 }
2153
2154 if (!isDryRun) {
2155 this.seen[originalSlug] = occurenceAccumulator;
2156 this.seen[slug] = 0;
2157 }
2158
2159 return slug;
2160 }
2161 /**
2162 * Convert string to unique id
2163 * @param {object} options
2164 * @param {boolean} options.dryrun Generates the next unique slug without updating the internal accumulator.
2165 */
2166 ;
2167
2168 _proto.slug = function slug(value, options) {
2169 if (options === void 0) {
2170 options = {};
2171 }
2172
2173 var slug = this.serialize(value);
2174 return this.getNextSafeSlug(slug, options.dryrun);
2175 };
2176
2177 return Slugger;
2178 }();
2179
2180 /**
2181 * Parsing & Compiling
2182 */
2183
2184 var Parser = /*#__PURE__*/function () {
2185 function Parser(options) {
2186 this.options = options || exports.defaults;
2187 this.options.renderer = this.options.renderer || new Renderer();
2188 this.renderer = this.options.renderer;
2189 this.renderer.options = this.options;
2190 this.textRenderer = new TextRenderer();
2191 this.slugger = new Slugger();
2192 }
2193 /**
2194 * Static Parse Method
2195 */
2196
2197
2198 Parser.parse = function parse(tokens, options) {
2199 var parser = new Parser(options);
2200 return parser.parse(tokens);
2201 }
2202 /**
2203 * Static Parse Inline Method
2204 */
2205 ;
2206
2207 Parser.parseInline = function parseInline(tokens, options) {
2208 var parser = new Parser(options);
2209 return parser.parseInline(tokens);
2210 }
2211 /**
2212 * Parse Loop
2213 */
2214 ;
2215
2216 var _proto = Parser.prototype;
2217
2218 _proto.parse = function parse(tokens, top) {
2219 if (top === void 0) {
2220 top = true;
2221 }
2222
2223 var out = '',
2224 i,
2225 j,
2226 k,
2227 l2,
2228 l3,
2229 row,
2230 cell,
2231 header,
2232 body,
2233 token,
2234 ordered,
2235 start,
2236 loose,
2237 itemBody,
2238 item,
2239 checked,
2240 task,
2241 checkbox,
2242 ret;
2243 var l = tokens.length;
2244
2245 for (i = 0; i < l; i++) {
2246 token = tokens[i]; // Run any renderer extensions
2247
2248 if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
2249 ret = this.options.extensions.renderers[token.type].call({
2250 parser: this
2251 }, token);
2252
2253 if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(token.type)) {
2254 out += ret || '';
2255 continue;
2256 }
2257 }
2258
2259 switch (token.type) {
2260 case 'space':
2261 {
2262 continue;
2263 }
2264
2265 case 'hr':
2266 {
2267 out += this.renderer.hr();
2268 continue;
2269 }
2270
2271 case 'heading':
2272 {
2273 out += this.renderer.heading(this.parseInline(token.tokens), token.depth, unescape(this.parseInline(token.tokens, this.textRenderer)), this.slugger);
2274 continue;
2275 }
2276
2277 case 'code':
2278 {
2279 out += this.renderer.code(token.text, token.lang, token.escaped);
2280 continue;
2281 }
2282
2283 case 'table':
2284 {
2285 header = ''; // header
2286
2287 cell = '';
2288 l2 = token.header.length;
2289
2290 for (j = 0; j < l2; j++) {
2291 cell += this.renderer.tablecell(this.parseInline(token.header[j].tokens), {
2292 header: true,
2293 align: token.align[j]
2294 });
2295 }
2296
2297 header += this.renderer.tablerow(cell);
2298 body = '';
2299 l2 = token.rows.length;
2300
2301 for (j = 0; j < l2; j++) {
2302 row = token.rows[j];
2303 cell = '';
2304 l3 = row.length;
2305
2306 for (k = 0; k < l3; k++) {
2307 cell += this.renderer.tablecell(this.parseInline(row[k].tokens), {
2308 header: false,
2309 align: token.align[k]
2310 });
2311 }
2312
2313 body += this.renderer.tablerow(cell);
2314 }
2315
2316 out += this.renderer.table(header, body);
2317 continue;
2318 }
2319
2320 case 'blockquote':
2321 {
2322 body = this.parse(token.tokens);
2323 out += this.renderer.blockquote(body);
2324 continue;
2325 }
2326
2327 case 'list':
2328 {
2329 ordered = token.ordered;
2330 start = token.start;
2331 loose = token.loose;
2332 l2 = token.items.length;
2333 body = '';
2334
2335 for (j = 0; j < l2; j++) {
2336 item = token.items[j];
2337 checked = item.checked;
2338 task = item.task;
2339 itemBody = '';
2340
2341 if (item.task) {
2342 checkbox = this.renderer.checkbox(checked);
2343
2344 if (loose) {
2345 if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
2346 item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
2347
2348 if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
2349 item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
2350 }
2351 } else {
2352 item.tokens.unshift({
2353 type: 'text',
2354 text: checkbox
2355 });
2356 }
2357 } else {
2358 itemBody += checkbox;
2359 }
2360 }
2361
2362 itemBody += this.parse(item.tokens, loose);
2363 body += this.renderer.listitem(itemBody, task, checked);
2364 }
2365
2366 out += this.renderer.list(body, ordered, start);
2367 continue;
2368 }
2369
2370 case 'html':
2371 {
2372 // TODO parse inline content if parameter markdown=1
2373 out += this.renderer.html(token.text);
2374 continue;
2375 }
2376
2377 case 'paragraph':
2378 {
2379 out += this.renderer.paragraph(this.parseInline(token.tokens));
2380 continue;
2381 }
2382
2383 case 'text':
2384 {
2385 body = token.tokens ? this.parseInline(token.tokens) : token.text;
2386
2387 while (i + 1 < l && tokens[i + 1].type === 'text') {
2388 token = tokens[++i];
2389 body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
2390 }
2391
2392 out += top ? this.renderer.paragraph(body) : body;
2393 continue;
2394 }
2395
2396 default:
2397 {
2398 var errMsg = 'Token with "' + token.type + '" type was not found.';
2399
2400 if (this.options.silent) {
2401 console.error(errMsg);
2402 return;
2403 } else {
2404 throw new Error(errMsg);
2405 }
2406 }
2407 }
2408 }
2409
2410 return out;
2411 }
2412 /**
2413 * Parse Inline Tokens
2414 */
2415 ;
2416
2417 _proto.parseInline = function parseInline(tokens, renderer) {
2418 renderer = renderer || this.renderer;
2419 var out = '',
2420 i,
2421 token,
2422 ret;
2423 var l = tokens.length;
2424
2425 for (i = 0; i < l; i++) {
2426 token = tokens[i]; // Run any renderer extensions
2427
2428 if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
2429 ret = this.options.extensions.renderers[token.type].call({
2430 parser: this
2431 }, token);
2432
2433 if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(token.type)) {
2434 out += ret || '';
2435 continue;
2436 }
2437 }
2438
2439 switch (token.type) {
2440 case 'escape':
2441 {
2442 out += renderer.text(token.text);
2443 break;
2444 }
2445
2446 case 'html':
2447 {
2448 out += renderer.html(token.text);
2449 break;
2450 }
2451
2452 case 'link':
2453 {
2454 out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
2455 break;
2456 }
2457
2458 case 'image':
2459 {
2460 out += renderer.image(token.href, token.title, token.text);
2461 break;
2462 }
2463
2464 case 'strong':
2465 {
2466 out += renderer.strong(this.parseInline(token.tokens, renderer));
2467 break;
2468 }
2469
2470 case 'em':
2471 {
2472 out += renderer.em(this.parseInline(token.tokens, renderer));
2473 break;
2474 }
2475
2476 case 'codespan':
2477 {
2478 out += renderer.codespan(token.text);
2479 break;
2480 }
2481
2482 case 'br':
2483 {
2484 out += renderer.br();
2485 break;
2486 }
2487
2488 case 'del':
2489 {
2490 out += renderer.del(this.parseInline(token.tokens, renderer));
2491 break;
2492 }
2493
2494 case 'text':
2495 {
2496 out += renderer.text(token.text);
2497 break;
2498 }
2499
2500 default:
2501 {
2502 var errMsg = 'Token with "' + token.type + '" type was not found.';
2503
2504 if (this.options.silent) {
2505 console.error(errMsg);
2506 return;
2507 } else {
2508 throw new Error(errMsg);
2509 }
2510 }
2511 }
2512 }
2513
2514 return out;
2515 };
2516
2517 return Parser;
2518 }();
2519
2520 /**
2521 * Marked
2522 */
2523
2524 function marked(src, opt, callback) {
2525 // throw error in case of non string input
2526 if (typeof src === 'undefined' || src === null) {
2527 throw new Error('marked(): input parameter is undefined or null');
2528 }
2529
2530 if (typeof src !== 'string') {
2531 throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
2532 }
2533
2534 if (typeof opt === 'function') {
2535 callback = opt;
2536 opt = null;
2537 }
2538
2539 opt = merge({}, marked.defaults, opt || {});
2540 checkSanitizeDeprecation(opt);
2541
2542 if (callback) {
2543 var highlight = opt.highlight;
2544 var tokens;
2545
2546 try {
2547 tokens = Lexer.lex(src, opt);
2548 } catch (e) {
2549 return callback(e);
2550 }
2551
2552 var done = function done(err) {
2553 var out;
2554
2555 if (!err) {
2556 try {
2557 if (opt.walkTokens) {
2558 marked.walkTokens(tokens, opt.walkTokens);
2559 }
2560
2561 out = Parser.parse(tokens, opt);
2562 } catch (e) {
2563 err = e;
2564 }
2565 }
2566
2567 opt.highlight = highlight;
2568 return err ? callback(err) : callback(null, out);
2569 };
2570
2571 if (!highlight || highlight.length < 3) {
2572 return done();
2573 }
2574
2575 delete opt.highlight;
2576 if (!tokens.length) return done();
2577 var pending = 0;
2578 marked.walkTokens(tokens, function (token) {
2579 if (token.type === 'code') {
2580 pending++;
2581 setTimeout(function () {
2582 highlight(token.text, token.lang, function (err, code) {
2583 if (err) {
2584 return done(err);
2585 }
2586
2587 if (code != null && code !== token.text) {
2588 token.text = code;
2589 token.escaped = true;
2590 }
2591
2592 pending--;
2593
2594 if (pending === 0) {
2595 done();
2596 }
2597 });
2598 }, 0);
2599 }
2600 });
2601
2602 if (pending === 0) {
2603 done();
2604 }
2605
2606 return;
2607 }
2608
2609 try {
2610 var _tokens = Lexer.lex(src, opt);
2611
2612 if (opt.walkTokens) {
2613 marked.walkTokens(_tokens, opt.walkTokens);
2614 }
2615
2616 return Parser.parse(_tokens, opt);
2617 } catch (e) {
2618 e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2619
2620 if (opt.silent) {
2621 return '<p>An error occurred:</p><pre>' + escape(e.message + '', true) + '</pre>';
2622 }
2623
2624 throw e;
2625 }
2626 }
2627 /**
2628 * Options
2629 */
2630
2631 marked.options = marked.setOptions = function (opt) {
2632 merge(marked.defaults, opt);
2633 changeDefaults(marked.defaults);
2634 return marked;
2635 };
2636
2637 marked.getDefaults = getDefaults;
2638 marked.defaults = exports.defaults;
2639 /**
2640 * Use Extension
2641 */
2642
2643 marked.use = function () {
2644 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2645 args[_key] = arguments[_key];
2646 }
2647
2648 var opts = merge.apply(void 0, [{}].concat(args));
2649 var extensions = marked.defaults.extensions || {
2650 renderers: {},
2651 childTokens: {}
2652 };
2653 var hasExtensions;
2654 args.forEach(function (pack) {
2655 // ==-- Parse "addon" extensions --== //
2656 if (pack.extensions) {
2657 hasExtensions = true;
2658 pack.extensions.forEach(function (ext) {
2659 if (!ext.name) {
2660 throw new Error('extension name required');
2661 }
2662
2663 if (ext.renderer) {
2664 // Renderer extensions
2665 var prevRenderer = extensions.renderers ? extensions.renderers[ext.name] : null;
2666
2667 if (prevRenderer) {
2668 // Replace extension with func to run new extension but fall back if false
2669 extensions.renderers[ext.name] = function () {
2670 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2671 args[_key2] = arguments[_key2];
2672 }
2673
2674 var ret = ext.renderer.apply(this, args);
2675
2676 if (ret === false) {
2677 ret = prevRenderer.apply(this, args);
2678 }
2679
2680 return ret;
2681 };
2682 } else {
2683 extensions.renderers[ext.name] = ext.renderer;
2684 }
2685 }
2686
2687 if (ext.tokenizer) {
2688 // Tokenizer Extensions
2689 if (!ext.level || ext.level !== 'block' && ext.level !== 'inline') {
2690 throw new Error("extension level must be 'block' or 'inline'");
2691 }
2692
2693 if (extensions[ext.level]) {
2694 extensions[ext.level].unshift(ext.tokenizer);
2695 } else {
2696 extensions[ext.level] = [ext.tokenizer];
2697 }
2698
2699 if (ext.start) {
2700 // Function to check for start of token
2701 if (ext.level === 'block') {
2702 if (extensions.startBlock) {
2703 extensions.startBlock.push(ext.start);
2704 } else {
2705 extensions.startBlock = [ext.start];
2706 }
2707 } else if (ext.level === 'inline') {
2708 if (extensions.startInline) {
2709 extensions.startInline.push(ext.start);
2710 } else {
2711 extensions.startInline = [ext.start];
2712 }
2713 }
2714 }
2715 }
2716
2717 if (ext.childTokens) {
2718 // Child tokens to be visited by walkTokens
2719 extensions.childTokens[ext.name] = ext.childTokens;
2720 }
2721 });
2722 } // ==-- Parse "overwrite" extensions --== //
2723
2724
2725 if (pack.renderer) {
2726 (function () {
2727 var renderer = marked.defaults.renderer || new Renderer();
2728
2729 var _loop = function _loop(prop) {
2730 var prevRenderer = renderer[prop]; // Replace renderer with func to run extension, but fall back if false
2731
2732 renderer[prop] = function () {
2733 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
2734 args[_key3] = arguments[_key3];
2735 }
2736
2737 var ret = pack.renderer[prop].apply(renderer, args);
2738
2739 if (ret === false) {
2740 ret = prevRenderer.apply(renderer, args);
2741 }
2742
2743 return ret;
2744 };
2745 };
2746
2747 for (var prop in pack.renderer) {
2748 _loop(prop);
2749 }
2750
2751 opts.renderer = renderer;
2752 })();
2753 }
2754
2755 if (pack.tokenizer) {
2756 (function () {
2757 var tokenizer = marked.defaults.tokenizer || new Tokenizer();
2758
2759 var _loop2 = function _loop2(prop) {
2760 var prevTokenizer = tokenizer[prop]; // Replace tokenizer with func to run extension, but fall back if false
2761
2762 tokenizer[prop] = function () {
2763 for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2764 args[_key4] = arguments[_key4];
2765 }
2766
2767 var ret = pack.tokenizer[prop].apply(tokenizer, args);
2768
2769 if (ret === false) {
2770 ret = prevTokenizer.apply(tokenizer, args);
2771 }
2772
2773 return ret;
2774 };
2775 };
2776
2777 for (var prop in pack.tokenizer) {
2778 _loop2(prop);
2779 }
2780
2781 opts.tokenizer = tokenizer;
2782 })();
2783 } // ==-- Parse WalkTokens extensions --== //
2784
2785
2786 if (pack.walkTokens) {
2787 var _walkTokens = marked.defaults.walkTokens;
2788
2789 opts.walkTokens = function (token) {
2790 pack.walkTokens.call(this, token);
2791
2792 if (_walkTokens) {
2793 _walkTokens.call(this, token);
2794 }
2795 };
2796 }
2797
2798 if (hasExtensions) {
2799 opts.extensions = extensions;
2800 }
2801
2802 marked.setOptions(opts);
2803 });
2804 };
2805 /**
2806 * Run callback for every token
2807 */
2808
2809
2810 marked.walkTokens = function (tokens, callback) {
2811 var _loop3 = function _loop3() {
2812 var token = _step.value;
2813 callback.call(marked, token);
2814
2815 switch (token.type) {
2816 case 'table':
2817 {
2818 for (var _iterator2 = _createForOfIteratorHelperLoose(token.header), _step2; !(_step2 = _iterator2()).done;) {
2819 var cell = _step2.value;
2820 marked.walkTokens(cell.tokens, callback);
2821 }
2822
2823 for (var _iterator3 = _createForOfIteratorHelperLoose(token.rows), _step3; !(_step3 = _iterator3()).done;) {
2824 var row = _step3.value;
2825
2826 for (var _iterator4 = _createForOfIteratorHelperLoose(row), _step4; !(_step4 = _iterator4()).done;) {
2827 var _cell = _step4.value;
2828 marked.walkTokens(_cell.tokens, callback);
2829 }
2830 }
2831
2832 break;
2833 }
2834
2835 case 'list':
2836 {
2837 marked.walkTokens(token.items, callback);
2838 break;
2839 }
2840
2841 default:
2842 {
2843 if (marked.defaults.extensions && marked.defaults.extensions.childTokens && marked.defaults.extensions.childTokens[token.type]) {
2844 // Walk any extensions
2845 marked.defaults.extensions.childTokens[token.type].forEach(function (childTokens) {
2846 marked.walkTokens(token[childTokens], callback);
2847 });
2848 } else if (token.tokens) {
2849 marked.walkTokens(token.tokens, callback);
2850 }
2851 }
2852 }
2853 };
2854
2855 for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
2856 _loop3();
2857 }
2858 };
2859 /**
2860 * Parse Inline
2861 */
2862
2863
2864 marked.parseInline = function (src, opt) {
2865 // throw error in case of non string input
2866 if (typeof src === 'undefined' || src === null) {
2867 throw new Error('marked.parseInline(): input parameter is undefined or null');
2868 }
2869
2870 if (typeof src !== 'string') {
2871 throw new Error('marked.parseInline(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
2872 }
2873
2874 opt = merge({}, marked.defaults, opt || {});
2875 checkSanitizeDeprecation(opt);
2876
2877 try {
2878 var tokens = Lexer.lexInline(src, opt);
2879
2880 if (opt.walkTokens) {
2881 marked.walkTokens(tokens, opt.walkTokens);
2882 }
2883
2884 return Parser.parseInline(tokens, opt);
2885 } catch (e) {
2886 e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2887
2888 if (opt.silent) {
2889 return '<p>An error occurred:</p><pre>' + escape(e.message + '', true) + '</pre>';
2890 }
2891
2892 throw e;
2893 }
2894 };
2895 /**
2896 * Expose
2897 */
2898
2899
2900 marked.Parser = Parser;
2901 marked.parser = Parser.parse;
2902 marked.Renderer = Renderer;
2903 marked.TextRenderer = TextRenderer;
2904 marked.Lexer = Lexer;
2905 marked.lexer = Lexer.lex;
2906 marked.Tokenizer = Tokenizer;
2907 marked.Slugger = Slugger;
2908 marked.parse = marked;
2909 var options = marked.options;
2910 var setOptions = marked.setOptions;
2911 var use = marked.use;
2912 var walkTokens = marked.walkTokens;
2913 var parseInline = marked.parseInline;
2914 var parse = marked;
2915 var parser = Parser.parse;
2916 var lexer = Lexer.lex;
2917
2918 exports.Lexer = Lexer;
2919 exports.Parser = Parser;
2920 exports.Renderer = Renderer;
2921 exports.Slugger = Slugger;
2922 exports.TextRenderer = TextRenderer;
2923 exports.Tokenizer = Tokenizer;
2924 exports.getDefaults = getDefaults;
2925 exports.lexer = lexer;
2926 exports.marked = marked;
2927 exports.options = options;
2928 exports.parse = parse;
2929 exports.parseInline = parseInline;
2930 exports.parser = parser;
2931 exports.setOptions = setOptions;
2932 exports.use = use;
2933 exports.walkTokens = walkTokens;
2934
2935 Object.defineProperty(exports, '__esModule', { value: true });
2936
2937}));