marked 1.2.9 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/marked.esm.js CHANGED
@@ -14,7 +14,7 @@ function createCommonjsModule(fn) {
14
14
  return fn(module, module.exports), module.exports;
15
15
  }
16
16
 
17
- var defaults = createCommonjsModule(function (module) {
17
+ var defaults$5 = createCommonjsModule(function (module) {
18
18
  function getDefaults() {
19
19
  return {
20
20
  baseUrl: null,
@@ -64,7 +64,7 @@ const escapeReplacements = {
64
64
  "'": '''
65
65
  };
66
66
  const getEscapeReplacement = (ch) => escapeReplacements[ch];
67
- function escape(html, encode) {
67
+ function escape$3(html, encode) {
68
68
  if (encode) {
69
69
  if (escapeTest.test(html)) {
70
70
  return html.replace(escapeReplace, getEscapeReplacement);
@@ -80,7 +80,7 @@ function escape(html, encode) {
80
80
 
81
81
  const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
82
82
 
83
- function unescape(html) {
83
+ function unescape$1(html) {
84
84
  // explicitly match decimal, hex, and named HTML entities
85
85
  return html.replace(unescapeTest, (_, n) => {
86
86
  n = n.toLowerCase();
@@ -95,7 +95,7 @@ function unescape(html) {
95
95
  }
96
96
 
97
97
  const caret = /(^|[^\[])\^/g;
98
- function edit(regex, opt) {
98
+ function edit$1(regex, opt) {
99
99
  regex = regex.source || regex;
100
100
  opt = opt || '';
101
101
  const obj = {
@@ -114,11 +114,11 @@ function edit(regex, opt) {
114
114
 
115
115
  const nonWordAndColonTest = /[^\w:]/g;
116
116
  const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
117
- function cleanUrl(sanitize, base, href) {
117
+ function cleanUrl$1(sanitize, base, href) {
118
118
  if (sanitize) {
119
119
  let prot;
120
120
  try {
121
- prot = decodeURIComponent(unescape(href))
121
+ prot = decodeURIComponent(unescape$1(href))
122
122
  .replace(nonWordAndColonTest, '')
123
123
  .toLowerCase();
124
124
  } catch (e) {
@@ -152,7 +152,7 @@ function resolveUrl(base, href) {
152
152
  if (justDomain.test(base)) {
153
153
  baseUrls[' ' + base] = base + '/';
154
154
  } else {
155
- baseUrls[' ' + base] = rtrim(base, '/', true);
155
+ baseUrls[' ' + base] = rtrim$1(base, '/', true);
156
156
  }
157
157
  }
158
158
  base = baseUrls[' ' + base];
@@ -173,9 +173,9 @@ function resolveUrl(base, href) {
173
173
  }
174
174
  }
175
175
 
176
- const noopTest = { exec: function noopTest() {} };
176
+ const noopTest$1 = { exec: function noopTest() {} };
177
177
 
178
- function merge(obj) {
178
+ function merge$2(obj) {
179
179
  let i = 1,
180
180
  target,
181
181
  key;
@@ -192,7 +192,7 @@ function merge(obj) {
192
192
  return obj;
193
193
  }
194
194
 
195
- function splitCells(tableRow, count) {
195
+ function splitCells$1(tableRow, count) {
196
196
  // ensure that every cell-delimiting pipe has a space
197
197
  // before it to distinguish it from an escaped pipe
198
198
  const row = tableRow.replace(/\|/g, (match, offset, str) => {
@@ -227,7 +227,7 @@ function splitCells(tableRow, count) {
227
227
  // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
228
228
  // /c*$/ is vulnerable to REDOS.
229
229
  // invert: Remove suffix of non-c chars instead. Default falsey.
230
- function rtrim(str, c, invert) {
230
+ function rtrim$1(str, c, invert) {
231
231
  const l = str.length;
232
232
  if (l === 0) {
233
233
  return '';
@@ -251,7 +251,7 @@ function rtrim(str, c, invert) {
251
251
  return str.substr(0, l - suffLen);
252
252
  }
253
253
 
254
- function findClosingBracket(str, b) {
254
+ function findClosingBracket$1(str, b) {
255
255
  if (str.indexOf(b[1]) === -1) {
256
256
  return -1;
257
257
  }
@@ -273,14 +273,14 @@ function findClosingBracket(str, b) {
273
273
  return -1;
274
274
  }
275
275
 
276
- function checkSanitizeDeprecation(opt) {
276
+ function checkSanitizeDeprecation$1(opt) {
277
277
  if (opt && opt.sanitize && !opt.silent) {
278
278
  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');
279
279
  }
280
280
  }
281
281
 
282
282
  // copied from https://stackoverflow.com/a/5450113/806777
283
- function repeatString(pattern, count) {
283
+ function repeatString$1(pattern, count) {
284
284
  if (count < 1) {
285
285
  return '';
286
286
  }
@@ -296,31 +296,31 @@ function repeatString(pattern, count) {
296
296
  }
297
297
 
298
298
  var helpers = {
299
- escape,
300
- unescape,
301
- edit,
302
- cleanUrl,
299
+ escape: escape$3,
300
+ unescape: unescape$1,
301
+ edit: edit$1,
302
+ cleanUrl: cleanUrl$1,
303
303
  resolveUrl,
304
- noopTest,
305
- merge,
306
- splitCells,
307
- rtrim,
308
- findClosingBracket,
309
- checkSanitizeDeprecation,
310
- repeatString
304
+ noopTest: noopTest$1,
305
+ merge: merge$2,
306
+ splitCells: splitCells$1,
307
+ rtrim: rtrim$1,
308
+ findClosingBracket: findClosingBracket$1,
309
+ checkSanitizeDeprecation: checkSanitizeDeprecation$1,
310
+ repeatString: repeatString$1
311
311
  };
312
312
 
313
- const { defaults: defaults$1 } = defaults;
313
+ const { defaults: defaults$4 } = defaults$5;
314
314
  const {
315
- rtrim: rtrim$1,
316
- splitCells: splitCells$1,
317
- escape: escape$1,
318
- findClosingBracket: findClosingBracket$1
315
+ rtrim,
316
+ splitCells,
317
+ escape: escape$2,
318
+ findClosingBracket
319
319
  } = helpers;
320
320
 
321
321
  function outputLink(cap, link, raw) {
322
322
  const href = link.href;
323
- const title = link.title ? escape$1(link.title) : null;
323
+ const title = link.title ? escape$2(link.title) : null;
324
324
  const text = cap[1].replace(/\\([\[\]])/g, '$1');
325
325
 
326
326
  if (cap[0].charAt(0) !== '!') {
@@ -337,7 +337,7 @@ function outputLink(cap, link, raw) {
337
337
  raw,
338
338
  href,
339
339
  title,
340
- text: escape$1(text)
340
+ text: escape$2(text)
341
341
  };
342
342
  }
343
343
  }
@@ -375,7 +375,7 @@ function indentCodeCompensation(raw, text) {
375
375
  */
376
376
  var Tokenizer_1 = class Tokenizer {
377
377
  constructor(options) {
378
- this.options = options || defaults$1;
378
+ this.options = options || defaults$4;
379
379
  }
380
380
 
381
381
  space(src) {
@@ -391,25 +391,16 @@ var Tokenizer_1 = class Tokenizer {
391
391
  }
392
392
  }
393
393
 
394
- code(src, tokens) {
394
+ code(src) {
395
395
  const cap = this.rules.block.code.exec(src);
396
396
  if (cap) {
397
- const lastToken = tokens[tokens.length - 1];
398
- // An indented code block cannot interrupt a paragraph.
399
- if (lastToken && lastToken.type === 'paragraph') {
400
- return {
401
- raw: cap[0],
402
- text: cap[0].trimRight()
403
- };
404
- }
405
-
406
397
  const text = cap[0].replace(/^ {1,4}/gm, '');
407
398
  return {
408
399
  type: 'code',
409
400
  raw: cap[0],
410
401
  codeBlockStyle: 'indented',
411
402
  text: !this.options.pedantic
412
- ? rtrim$1(text, '\n')
403
+ ? rtrim(text, '\n')
413
404
  : text
414
405
  };
415
406
  }
@@ -437,7 +428,7 @@ var Tokenizer_1 = class Tokenizer {
437
428
 
438
429
  // remove trailing #s
439
430
  if (/#$/.test(text)) {
440
- const trimmed = rtrim$1(text, '#');
431
+ const trimmed = rtrim(text, '#');
441
432
  if (this.options.pedantic) {
442
433
  text = trimmed.trim();
443
434
  } else if (!trimmed || / $/.test(trimmed)) {
@@ -460,7 +451,7 @@ var Tokenizer_1 = class Tokenizer {
460
451
  if (cap) {
461
452
  const item = {
462
453
  type: 'table',
463
- header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
454
+ header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
464
455
  align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
465
456
  cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [],
466
457
  raw: cap[0]
@@ -483,7 +474,7 @@ var Tokenizer_1 = class Tokenizer {
483
474
 
484
475
  l = item.cells.length;
485
476
  for (i = 0; i < l; i++) {
486
- item.cells[i] = splitCells$1(item.cells[i], item.header.length);
477
+ item.cells[i] = splitCells(item.cells[i], item.header.length);
487
478
  }
488
479
 
489
480
  return item;
@@ -541,7 +532,8 @@ var Tokenizer_1 = class Tokenizer {
541
532
  addBack,
542
533
  loose,
543
534
  istask,
544
- ischecked;
535
+ ischecked,
536
+ endMatch;
545
537
 
546
538
  let l = itemMatch.length;
547
539
  bcurr = this.rules.block.listItemStart.exec(itemMatch[0]);
@@ -549,31 +541,42 @@ var Tokenizer_1 = class Tokenizer {
549
541
  item = itemMatch[i];
550
542
  raw = item;
551
543
 
544
+ if (!this.options.pedantic) {
545
+ // Determine if current item contains the end of the list
546
+ endMatch = item.match(new RegExp('\\n\\s*\\n {0,' + (bcurr[0].length - 1) + '}\\S'));
547
+ if (endMatch) {
548
+ addBack = item.length - endMatch.index + itemMatch.slice(i + 1).join('\n').length;
549
+ list.raw = list.raw.substring(0, list.raw.length - addBack);
550
+
551
+ item = item.substring(0, endMatch.index);
552
+ raw = item;
553
+ l = i + 1;
554
+ }
555
+ }
556
+
552
557
  // Determine whether the next list item belongs here.
553
558
  // Backpedal if it does not belong in this list.
554
559
  if (i !== l - 1) {
555
560
  bnext = this.rules.block.listItemStart.exec(itemMatch[i + 1]);
556
561
  if (
557
562
  !this.options.pedantic
558
- ? bnext[1].length > bcurr[0].length || bnext[1].length > 3
563
+ ? bnext[1].length >= bcurr[0].length || bnext[1].length > 3
559
564
  : bnext[1].length > bcurr[1].length
560
565
  ) {
561
- // nested list
562
- itemMatch.splice(i, 2, itemMatch[i] + '\n' + itemMatch[i + 1]);
566
+ // nested list or continuation
567
+ itemMatch.splice(i, 2, itemMatch[i] + (!this.options.pedantic && bnext[1].length < bcurr[0].length && !itemMatch[i].match(/\n$/) ? '' : '\n') + itemMatch[i + 1]);
563
568
  i--;
564
569
  l--;
565
570
  continue;
566
- } else {
567
- if (
568
- // different bullet style
569
- !this.options.pedantic || this.options.smartLists
570
- ? bnext[2][bnext[2].length - 1] !== bull[bull.length - 1]
571
- : isordered === (bnext[2].length === 1)
572
- ) {
573
- addBack = itemMatch.slice(i + 1).join('\n');
574
- list.raw = list.raw.substring(0, list.raw.length - addBack.length);
575
- i = l - 1;
576
- }
571
+ } else if (
572
+ // different bullet style
573
+ !this.options.pedantic || this.options.smartLists
574
+ ? bnext[2][bnext[2].length - 1] !== bull[bull.length - 1]
575
+ : isordered === (bnext[2].length === 1)
576
+ ) {
577
+ addBack = itemMatch.slice(i + 1).join('\n').length;
578
+ list.raw = list.raw.substring(0, list.raw.length - addBack);
579
+ i = l - 1;
577
580
  }
578
581
  bcurr = bnext;
579
582
  }
@@ -592,12 +595,18 @@ var Tokenizer_1 = class Tokenizer {
592
595
  : item.replace(/^ {1,4}/gm, '');
593
596
  }
594
597
 
598
+ // trim item newlines at end
599
+ item = rtrim(item, '\n');
600
+ if (i !== l - 1) {
601
+ raw = raw + '\n';
602
+ }
603
+
595
604
  // Determine whether item is loose or not.
596
605
  // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
597
606
  // for discount behavior.
598
- loose = next || /\n\n(?!\s*$)/.test(item);
607
+ loose = next || /\n\n(?!\s*$)/.test(raw);
599
608
  if (i !== l - 1) {
600
- next = item.charAt(item.length - 1) === '\n';
609
+ next = raw.slice(-2) === '\n\n';
601
610
  if (!loose) loose = next;
602
611
  }
603
612
 
@@ -639,7 +648,7 @@ var Tokenizer_1 = class Tokenizer {
639
648
  raw: cap[0],
640
649
  pre: !this.options.sanitizer
641
650
  && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
642
- text: this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$1(cap[0])) : cap[0]
651
+ text: this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$2(cap[0])) : cap[0]
643
652
  };
644
653
  }
645
654
  }
@@ -650,6 +659,7 @@ var Tokenizer_1 = class Tokenizer {
650
659
  if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
651
660
  const tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
652
661
  return {
662
+ type: 'def',
653
663
  tag,
654
664
  raw: cap[0],
655
665
  href: cap[2],
@@ -663,7 +673,7 @@ var Tokenizer_1 = class Tokenizer {
663
673
  if (cap) {
664
674
  const item = {
665
675
  type: 'table',
666
- header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
676
+ header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
667
677
  align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
668
678
  cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
669
679
  };
@@ -687,7 +697,7 @@ var Tokenizer_1 = class Tokenizer {
687
697
 
688
698
  l = item.cells.length;
689
699
  for (i = 0; i < l; i++) {
690
- item.cells[i] = splitCells$1(
700
+ item.cells[i] = splitCells(
691
701
  item.cells[i].replace(/^ *\| *| *\| *$/g, ''),
692
702
  item.header.length);
693
703
  }
@@ -722,17 +732,9 @@ var Tokenizer_1 = class Tokenizer {
722
732
  }
723
733
  }
724
734
 
725
- text(src, tokens) {
735
+ text(src) {
726
736
  const cap = this.rules.block.text.exec(src);
727
737
  if (cap) {
728
- const lastToken = tokens[tokens.length - 1];
729
- if (lastToken && lastToken.type === 'text') {
730
- return {
731
- raw: cap[0],
732
- text: cap[0]
733
- };
734
- }
735
-
736
738
  return {
737
739
  type: 'text',
738
740
  raw: cap[0],
@@ -747,7 +749,7 @@ var Tokenizer_1 = class Tokenizer {
747
749
  return {
748
750
  type: 'escape',
749
751
  raw: cap[0],
750
- text: escape$1(cap[1])
752
+ text: escape$2(cap[1])
751
753
  };
752
754
  }
753
755
  }
@@ -776,7 +778,7 @@ var Tokenizer_1 = class Tokenizer {
776
778
  text: this.options.sanitize
777
779
  ? (this.options.sanitizer
778
780
  ? this.options.sanitizer(cap[0])
779
- : escape$1(cap[0]))
781
+ : escape$2(cap[0]))
780
782
  : cap[0]
781
783
  };
782
784
  }
@@ -793,13 +795,13 @@ var Tokenizer_1 = class Tokenizer {
793
795
  }
794
796
 
795
797
  // ending angle bracket cannot be escaped
796
- const rtrimSlash = rtrim$1(trimmedUrl.slice(0, -1), '\\');
798
+ const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), '\\');
797
799
  if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
798
800
  return;
799
801
  }
800
802
  } else {
801
803
  // find closing parenthesis
802
- const lastParenIndex = findClosingBracket$1(cap[2], '()');
804
+ const lastParenIndex = findClosingBracket(cap[2], '()');
803
805
  if (lastParenIndex > -1) {
804
806
  const start = cap[0].indexOf('!') === 0 ? 5 : 4;
805
807
  const linkLen = start + cap[1].length + lastParenIndex;
@@ -856,46 +858,61 @@ var Tokenizer_1 = class Tokenizer {
856
858
  }
857
859
  }
858
860
 
859
- strong(src, maskedSrc, prevChar = '') {
860
- let match = this.rules.inline.strong.start.exec(src);
861
+ emStrong(src, maskedSrc, prevChar = '') {
862
+ let match = this.rules.inline.emStrong.lDelim.exec(src);
863
+ if (!match) return;
864
+
865
+ if (match[3] && prevChar.match(/[\p{L}\p{N}]/u)) return; // _ can't be between two alphanumerics. \p{L}\p{N} includes non-english alphabet/numbers as well
861
866
 
862
- if (match && (!match[1] || (match[1] && (prevChar === '' || this.rules.inline.punctuation.exec(prevChar))))) {
863
- maskedSrc = maskedSrc.slice(-1 * src.length);
864
- const endReg = match[0] === '**' ? this.rules.inline.strong.endAst : this.rules.inline.strong.endUnd;
867
+ const nextChar = match[1] || match[2] || '';
865
868
 
869
+ if (!nextChar || (nextChar && (prevChar === '' || this.rules.inline.punctuation.exec(prevChar)))) {
870
+ const lLength = match[0].length - 1;
871
+ let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
872
+
873
+ const endReg = match[0][0] === '*' ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
866
874
  endReg.lastIndex = 0;
867
875
 
868
- let cap;
876
+ maskedSrc = maskedSrc.slice(-1 * src.length + lLength); // Bump maskedSrc to same section of string as src (move to lexer?)
877
+
869
878
  while ((match = endReg.exec(maskedSrc)) != null) {
870
- cap = this.rules.inline.strong.middle.exec(maskedSrc.slice(0, match.index + 3));
871
- if (cap) {
872
- return {
873
- type: 'strong',
874
- raw: src.slice(0, cap[0].length),
875
- text: src.slice(2, cap[0].length - 2)
876
- };
879
+ rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
880
+
881
+ if (!rDelim) continue; // matched the first alternative in rules.js (skip the * in __abc*abc__)
882
+
883
+ rLength = rDelim.length;
884
+
885
+ if (match[3] || match[4]) { // found another Left Delim
886
+ delimTotal += rLength;
887
+ continue;
888
+ } else if (match[5] || match[6]) { // either Left or Right Delim
889
+ if (lLength % 3 && !((lLength + rLength) % 3)) {
890
+ midDelimTotal += rLength;
891
+ continue; // CommonMark Emphasis Rules 9-10
892
+ }
877
893
  }
878
- }
879
- }
880
- }
881
894
 
882
- em(src, maskedSrc, prevChar = '') {
883
- let match = this.rules.inline.em.start.exec(src);
895
+ delimTotal -= rLength;
884
896
 
885
- if (match && (!match[1] || (match[1] && (prevChar === '' || this.rules.inline.punctuation.exec(prevChar))))) {
886
- maskedSrc = maskedSrc.slice(-1 * src.length);
887
- const endReg = match[0] === '*' ? this.rules.inline.em.endAst : this.rules.inline.em.endUnd;
897
+ if (delimTotal > 0) continue; // Haven't found enough closing delimiters
888
898
 
889
- endReg.lastIndex = 0;
899
+ // If this is the last rDelimiter, remove extra characters. *a*** -> *a*
900
+ if (delimTotal + midDelimTotal - rLength <= 0 && !maskedSrc.slice(endReg.lastIndex).match(endReg)) {
901
+ rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
902
+ }
890
903
 
891
- let cap;
892
- while ((match = endReg.exec(maskedSrc)) != null) {
893
- cap = this.rules.inline.em.middle.exec(maskedSrc.slice(0, match.index + 2));
894
- if (cap) {
904
+ if (Math.min(lLength, rLength) % 2) {
895
905
  return {
896
906
  type: 'em',
897
- raw: src.slice(0, cap[0].length),
898
- text: src.slice(1, cap[0].length - 1)
907
+ raw: src.slice(0, lLength + match.index + rLength + 1),
908
+ text: src.slice(1, lLength + match.index + rLength)
909
+ };
910
+ }
911
+ if (Math.min(lLength, rLength) % 2 === 0) {
912
+ return {
913
+ type: 'strong',
914
+ raw: src.slice(0, lLength + match.index + rLength + 1),
915
+ text: src.slice(2, lLength + match.index + rLength - 1)
899
916
  };
900
917
  }
901
918
  }
@@ -911,7 +928,7 @@ var Tokenizer_1 = class Tokenizer {
911
928
  if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
912
929
  text = text.substring(1, text.length - 1);
913
930
  }
914
- text = escape$1(text, true);
931
+ text = escape$2(text, true);
915
932
  return {
916
933
  type: 'codespan',
917
934
  raw: cap[0],
@@ -946,10 +963,10 @@ var Tokenizer_1 = class Tokenizer {
946
963
  if (cap) {
947
964
  let text, href;
948
965
  if (cap[2] === '@') {
949
- text = escape$1(this.options.mangle ? mangle(cap[1]) : cap[1]);
966
+ text = escape$2(this.options.mangle ? mangle(cap[1]) : cap[1]);
950
967
  href = 'mailto:' + text;
951
968
  } else {
952
- text = escape$1(cap[1]);
969
+ text = escape$2(cap[1]);
953
970
  href = text;
954
971
  }
955
972
 
@@ -974,7 +991,7 @@ var Tokenizer_1 = class Tokenizer {
974
991
  if (cap = this.rules.inline.url.exec(src)) {
975
992
  let text, href;
976
993
  if (cap[2] === '@') {
977
- text = escape$1(this.options.mangle ? mangle(cap[0]) : cap[0]);
994
+ text = escape$2(this.options.mangle ? mangle(cap[0]) : cap[0]);
978
995
  href = 'mailto:' + text;
979
996
  } else {
980
997
  // do extended autolink path validation
@@ -983,7 +1000,7 @@ var Tokenizer_1 = class Tokenizer {
983
1000
  prevCapZero = cap[0];
984
1001
  cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
985
1002
  } while (prevCapZero !== cap[0]);
986
- text = escape$1(cap[0]);
1003
+ text = escape$2(cap[0]);
987
1004
  if (cap[1] === 'www.') {
988
1005
  href = 'http://' + text;
989
1006
  } else {
@@ -1011,9 +1028,9 @@ var Tokenizer_1 = class Tokenizer {
1011
1028
  if (cap) {
1012
1029
  let text;
1013
1030
  if (inRawBlock) {
1014
- text = this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$1(cap[0])) : cap[0];
1031
+ text = this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$2(cap[0])) : cap[0];
1015
1032
  } else {
1016
- text = escape$1(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
1033
+ text = escape$2(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
1017
1034
  }
1018
1035
  return {
1019
1036
  type: 'text',
@@ -1025,15 +1042,15 @@ var Tokenizer_1 = class Tokenizer {
1025
1042
  };
1026
1043
 
1027
1044
  const {
1028
- noopTest: noopTest$1,
1029
- edit: edit$1,
1045
+ noopTest,
1046
+ edit,
1030
1047
  merge: merge$1
1031
1048
  } = helpers;
1032
1049
 
1033
1050
  /**
1034
1051
  * Block-Level Grammar
1035
1052
  */
1036
- const block = {
1053
+ const block$1 = {
1037
1054
  newline: /^(?: *(?:\n|$))+/,
1038
1055
  code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
1039
1056
  fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
@@ -1052,8 +1069,8 @@ const block = {
1052
1069
  + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
1053
1070
  + ')',
1054
1071
  def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
1055
- nptable: noopTest$1,
1056
- table: noopTest$1,
1072
+ nptable: noopTest,
1073
+ table: noopTest,
1057
1074
  lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
1058
1075
  // regex template, placeholders will be replaced according to different paragraph
1059
1076
  // interruption rules of commonmark and the original markdown spec:
@@ -1061,68 +1078,68 @@ const block = {
1061
1078
  text: /^[^\n]+/
1062
1079
  };
1063
1080
 
1064
- block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
1065
- block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
1066
- block.def = edit$1(block.def)
1067
- .replace('label', block._label)
1068
- .replace('title', block._title)
1081
+ block$1._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
1082
+ block$1._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
1083
+ block$1.def = edit(block$1.def)
1084
+ .replace('label', block$1._label)
1085
+ .replace('title', block$1._title)
1069
1086
  .getRegex();
1070
1087
 
1071
- block.bullet = /(?:[*+-]|\d{1,9}[.)])/;
1072
- block.item = /^( *)(bull) ?[^\n]*(?:\n(?! *bull ?)[^\n]*)*/;
1073
- block.item = edit$1(block.item, 'gm')
1074
- .replace(/bull/g, block.bullet)
1088
+ block$1.bullet = /(?:[*+-]|\d{1,9}[.)])/;
1089
+ block$1.item = /^( *)(bull) ?[^\n]*(?:\n(?! *bull ?)[^\n]*)*/;
1090
+ block$1.item = edit(block$1.item, 'gm')
1091
+ .replace(/bull/g, block$1.bullet)
1075
1092
  .getRegex();
1076
1093
 
1077
- block.listItemStart = edit$1(/^( *)(bull)/)
1078
- .replace('bull', block.bullet)
1094
+ block$1.listItemStart = edit(/^( *)(bull) */)
1095
+ .replace('bull', block$1.bullet)
1079
1096
  .getRegex();
1080
1097
 
1081
- block.list = edit$1(block.list)
1082
- .replace(/bull/g, block.bullet)
1098
+ block$1.list = edit(block$1.list)
1099
+ .replace(/bull/g, block$1.bullet)
1083
1100
  .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
1084
- .replace('def', '\\n+(?=' + block.def.source + ')')
1101
+ .replace('def', '\\n+(?=' + block$1.def.source + ')')
1085
1102
  .getRegex();
1086
1103
 
1087
- block._tag = 'address|article|aside|base|basefont|blockquote|body|caption'
1104
+ block$1._tag = 'address|article|aside|base|basefont|blockquote|body|caption'
1088
1105
  + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption'
1089
1106
  + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe'
1090
1107
  + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option'
1091
1108
  + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr'
1092
1109
  + '|track|ul';
1093
- block._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;
1094
- block.html = edit$1(block.html, 'i')
1095
- .replace('comment', block._comment)
1096
- .replace('tag', block._tag)
1110
+ block$1._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;
1111
+ block$1.html = edit(block$1.html, 'i')
1112
+ .replace('comment', block$1._comment)
1113
+ .replace('tag', block$1._tag)
1097
1114
  .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
1098
1115
  .getRegex();
1099
1116
 
1100
- block.paragraph = edit$1(block._paragraph)
1101
- .replace('hr', block.hr)
1117
+ block$1.paragraph = edit(block$1._paragraph)
1118
+ .replace('hr', block$1.hr)
1102
1119
  .replace('heading', ' {0,3}#{1,6} ')
1103
1120
  .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
1104
1121
  .replace('blockquote', ' {0,3}>')
1105
1122
  .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1106
1123
  .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1107
1124
  .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
1108
- .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
1125
+ .replace('tag', block$1._tag) // pars can be interrupted by type (6) html blocks
1109
1126
  .getRegex();
1110
1127
 
1111
- block.blockquote = edit$1(block.blockquote)
1112
- .replace('paragraph', block.paragraph)
1128
+ block$1.blockquote = edit(block$1.blockquote)
1129
+ .replace('paragraph', block$1.paragraph)
1113
1130
  .getRegex();
1114
1131
 
1115
1132
  /**
1116
1133
  * Normal Block Grammar
1117
1134
  */
1118
1135
 
1119
- block.normal = merge$1({}, block);
1136
+ block$1.normal = merge$1({}, block$1);
1120
1137
 
1121
1138
  /**
1122
1139
  * GFM Block Grammar
1123
1140
  */
1124
1141
 
1125
- block.gfm = merge$1({}, block.normal, {
1142
+ block$1.gfm = merge$1({}, block$1.normal, {
1126
1143
  nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
1127
1144
  + ' {0,3}([-:]+ *\\|[-| :]*)' // Align
1128
1145
  + '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)', // Cells
@@ -1131,38 +1148,38 @@ block.gfm = merge$1({}, block.normal, {
1131
1148
  + '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
1132
1149
  });
1133
1150
 
1134
- block.gfm.nptable = edit$1(block.gfm.nptable)
1135
- .replace('hr', block.hr)
1151
+ block$1.gfm.nptable = edit(block$1.gfm.nptable)
1152
+ .replace('hr', block$1.hr)
1136
1153
  .replace('heading', ' {0,3}#{1,6} ')
1137
1154
  .replace('blockquote', ' {0,3}>')
1138
1155
  .replace('code', ' {4}[^\\n]')
1139
1156
  .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1140
1157
  .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1141
1158
  .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
1142
- .replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
1159
+ .replace('tag', block$1._tag) // tables can be interrupted by type (6) html blocks
1143
1160
  .getRegex();
1144
1161
 
1145
- block.gfm.table = edit$1(block.gfm.table)
1146
- .replace('hr', block.hr)
1162
+ block$1.gfm.table = edit(block$1.gfm.table)
1163
+ .replace('hr', block$1.hr)
1147
1164
  .replace('heading', ' {0,3}#{1,6} ')
1148
1165
  .replace('blockquote', ' {0,3}>')
1149
1166
  .replace('code', ' {4}[^\\n]')
1150
1167
  .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1151
1168
  .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1152
1169
  .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
1153
- .replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
1170
+ .replace('tag', block$1._tag) // tables can be interrupted by type (6) html blocks
1154
1171
  .getRegex();
1155
1172
 
1156
1173
  /**
1157
1174
  * Pedantic grammar (original John Gruber's loose markdown specification)
1158
1175
  */
1159
1176
 
1160
- block.pedantic = merge$1({}, block.normal, {
1161
- html: edit$1(
1177
+ block$1.pedantic = merge$1({}, block$1.normal, {
1178
+ html: edit(
1162
1179
  '^ *(?:comment *(?:\\n|\\s*$)'
1163
1180
  + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
1164
1181
  + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))')
1165
- .replace('comment', block._comment)
1182
+ .replace('comment', block$1._comment)
1166
1183
  .replace(/tag/g, '(?!(?:'
1167
1184
  + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'
1168
1185
  + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'
@@ -1170,11 +1187,11 @@ block.pedantic = merge$1({}, block.normal, {
1170
1187
  .getRegex(),
1171
1188
  def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
1172
1189
  heading: /^(#{1,6})(.*)(?:\n+|$)/,
1173
- fences: noopTest$1, // fences not supported
1174
- paragraph: edit$1(block.normal._paragraph)
1175
- .replace('hr', block.hr)
1190
+ fences: noopTest, // fences not supported
1191
+ paragraph: edit(block$1.normal._paragraph)
1192
+ .replace('hr', block$1.hr)
1176
1193
  .replace('heading', ' *#{1,6} *[^\n]')
1177
- .replace('lheading', block.lheading)
1194
+ .replace('lheading', block$1.lheading)
1178
1195
  .replace('blockquote', ' {0,3}>')
1179
1196
  .replace('|fences', '')
1180
1197
  .replace('|list', '')
@@ -1185,10 +1202,10 @@ block.pedantic = merge$1({}, block.normal, {
1185
1202
  /**
1186
1203
  * Inline-Level Grammar
1187
1204
  */
1188
- const inline = {
1205
+ const inline$1 = {
1189
1206
  escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
1190
1207
  autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
1191
- url: noopTest$1,
1208
+ url: noopTest,
1192
1209
  tag: '^comment'
1193
1210
  + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
1194
1211
  + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
@@ -1199,122 +1216,89 @@ const inline = {
1199
1216
  reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
1200
1217
  nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
1201
1218
  reflinkSearch: 'reflink|nolink(?!\\()',
1202
- strong: {
1203
- start: /^(?:(\*\*(?=[*punctuation]))|\*\*)(?![\s])|__/, // (1) returns if starts w/ punctuation
1204
- middle: /^\*\*(?:(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)|\*(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)*?\*)+?\*\*$|^__(?![\s])((?:(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)|_(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)*?_)+?)__$/,
1205
- endAst: /[^punctuation\s]\*\*(?!\*)|[punctuation]\*\*(?!\*)(?:(?=[punctuation_\s]|$))/, // last char can't be punct, or final * must also be followed by punct (or endline)
1206
- endUnd: /[^\s]__(?!_)(?:(?=[punctuation*\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
1207
- },
1208
- em: {
1209
- start: /^(?:(\*(?=[punctuation]))|\*)(?![*\s])|_/, // (1) returns if starts w/ punctuation
1210
- middle: /^\*(?:(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)|\*(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)*?\*)+?\*$|^_(?![_\s])(?:(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)|_(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)*?_)+?_$/,
1211
- endAst: /[^punctuation\s]\*(?!\*)|[punctuation]\*(?!\*)(?:(?=[punctuation_\s]|$))/, // last char can't be punct, or final * must also be followed by punct (or endline)
1212
- endUnd: /[^\s]_(?!_)(?:(?=[punctuation*\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
1219
+ emStrong: {
1220
+ lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
1221
+ // (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.
1222
+ // () Skip other delimiter (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
1223
+ rDelimAst: /\_\_[^_]*?\*[^_]*?\_\_|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
1224
+ rDelimUnd: /\*\*[^*]*?\_[^*]*?\*\*|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
1213
1225
  },
1214
1226
  code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
1215
1227
  br: /^( {2,}|\\)\n(?!\s*$)/,
1216
- del: noopTest$1,
1217
- text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n)))/,
1218
- punctuation: /^([\s*punctuation])/
1228
+ del: noopTest,
1229
+ text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
1230
+ punctuation: /^([\spunctuation])/
1219
1231
  };
1220
1232
 
1221
- // list of punctuation marks from common mark spec
1222
- // without * and _ to workaround cases with double emphasis
1223
- inline._punctuation = '!"#$%&\'()+\\-.,/:;<=>?@\\[\\]`^{|}~';
1224
- inline.punctuation = edit$1(inline.punctuation).replace(/punctuation/g, inline._punctuation).getRegex();
1233
+ // list of punctuation marks from CommonMark spec
1234
+ // without * and _ to handle the different emphasis markers * and _
1235
+ inline$1._punctuation = '!"#$%&\'()+\\-.,/:;<=>?@\\[\\]`^{|}~';
1236
+ inline$1.punctuation = edit(inline$1.punctuation).replace(/punctuation/g, inline$1._punctuation).getRegex();
1225
1237
 
1226
1238
  // sequences em should skip over [title](link), `code`, <html>
1227
- inline._blockSkip = '\\[[^\\]]*?\\]\\([^\\)]*?\\)|`[^`]*?`|<[^>]*?>';
1228
- inline._overlapSkip = '__[^_]*?__|\\*\\*\\[^\\*\\]*?\\*\\*';
1229
-
1230
- inline._comment = edit$1(block._comment).replace('(?:-->|$)', '-->').getRegex();
1231
-
1232
- inline.em.start = edit$1(inline.em.start)
1233
- .replace(/punctuation/g, inline._punctuation)
1234
- .getRegex();
1235
-
1236
- inline.em.middle = edit$1(inline.em.middle)
1237
- .replace(/punctuation/g, inline._punctuation)
1238
- .replace(/overlapSkip/g, inline._overlapSkip)
1239
- .getRegex();
1240
-
1241
- inline.em.endAst = edit$1(inline.em.endAst, 'g')
1242
- .replace(/punctuation/g, inline._punctuation)
1243
- .getRegex();
1244
-
1245
- inline.em.endUnd = edit$1(inline.em.endUnd, 'g')
1246
- .replace(/punctuation/g, inline._punctuation)
1247
- .getRegex();
1239
+ inline$1.blockSkip = /\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;
1240
+ inline$1.escapedEmSt = /\\\*|\\_/g;
1248
1241
 
1249
- inline.strong.start = edit$1(inline.strong.start)
1250
- .replace(/punctuation/g, inline._punctuation)
1251
- .getRegex();
1242
+ inline$1._comment = edit(block$1._comment).replace('(?:-->|$)', '-->').getRegex();
1252
1243
 
1253
- inline.strong.middle = edit$1(inline.strong.middle)
1254
- .replace(/punctuation/g, inline._punctuation)
1255
- .replace(/overlapSkip/g, inline._overlapSkip)
1244
+ inline$1.emStrong.lDelim = edit(inline$1.emStrong.lDelim)
1245
+ .replace(/punct/g, inline$1._punctuation)
1256
1246
  .getRegex();
1257
1247
 
1258
- inline.strong.endAst = edit$1(inline.strong.endAst, 'g')
1259
- .replace(/punctuation/g, inline._punctuation)
1248
+ inline$1.emStrong.rDelimAst = edit(inline$1.emStrong.rDelimAst, 'g')
1249
+ .replace(/punct/g, inline$1._punctuation)
1260
1250
  .getRegex();
1261
1251
 
1262
- inline.strong.endUnd = edit$1(inline.strong.endUnd, 'g')
1263
- .replace(/punctuation/g, inline._punctuation)
1252
+ inline$1.emStrong.rDelimUnd = edit(inline$1.emStrong.rDelimUnd, 'g')
1253
+ .replace(/punct/g, inline$1._punctuation)
1264
1254
  .getRegex();
1265
1255
 
1266
- inline.blockSkip = edit$1(inline._blockSkip, 'g')
1267
- .getRegex();
1256
+ inline$1._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
1268
1257
 
1269
- inline.overlapSkip = edit$1(inline._overlapSkip, 'g')
1258
+ inline$1._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
1259
+ inline$1._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])?)+(?![-_])/;
1260
+ inline$1.autolink = edit(inline$1.autolink)
1261
+ .replace('scheme', inline$1._scheme)
1262
+ .replace('email', inline$1._email)
1270
1263
  .getRegex();
1271
1264
 
1272
- inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
1265
+ inline$1._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
1273
1266
 
1274
- inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
1275
- 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])?)+(?![-_])/;
1276
- inline.autolink = edit$1(inline.autolink)
1277
- .replace('scheme', inline._scheme)
1278
- .replace('email', inline._email)
1267
+ inline$1.tag = edit(inline$1.tag)
1268
+ .replace('comment', inline$1._comment)
1269
+ .replace('attribute', inline$1._attribute)
1279
1270
  .getRegex();
1280
1271
 
1281
- inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
1272
+ inline$1._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
1273
+ inline$1._href = /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/;
1274
+ inline$1._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
1282
1275
 
1283
- inline.tag = edit$1(inline.tag)
1284
- .replace('comment', inline._comment)
1285
- .replace('attribute', inline._attribute)
1276
+ inline$1.link = edit(inline$1.link)
1277
+ .replace('label', inline$1._label)
1278
+ .replace('href', inline$1._href)
1279
+ .replace('title', inline$1._title)
1286
1280
  .getRegex();
1287
1281
 
1288
- inline._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
1289
- inline._href = /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/;
1290
- inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
1291
-
1292
- inline.link = edit$1(inline.link)
1293
- .replace('label', inline._label)
1294
- .replace('href', inline._href)
1295
- .replace('title', inline._title)
1282
+ inline$1.reflink = edit(inline$1.reflink)
1283
+ .replace('label', inline$1._label)
1296
1284
  .getRegex();
1297
1285
 
1298
- inline.reflink = edit$1(inline.reflink)
1299
- .replace('label', inline._label)
1300
- .getRegex();
1301
-
1302
- inline.reflinkSearch = edit$1(inline.reflinkSearch, 'g')
1303
- .replace('reflink', inline.reflink)
1304
- .replace('nolink', inline.nolink)
1286
+ inline$1.reflinkSearch = edit(inline$1.reflinkSearch, 'g')
1287
+ .replace('reflink', inline$1.reflink)
1288
+ .replace('nolink', inline$1.nolink)
1305
1289
  .getRegex();
1306
1290
 
1307
1291
  /**
1308
1292
  * Normal Inline Grammar
1309
1293
  */
1310
1294
 
1311
- inline.normal = merge$1({}, inline);
1295
+ inline$1.normal = merge$1({}, inline$1);
1312
1296
 
1313
1297
  /**
1314
1298
  * Pedantic Inline Grammar
1315
1299
  */
1316
1300
 
1317
- inline.pedantic = merge$1({}, inline.normal, {
1301
+ inline$1.pedantic = merge$1({}, inline$1.normal, {
1318
1302
  strong: {
1319
1303
  start: /^__|\*\*/,
1320
1304
  middle: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
@@ -1327,11 +1311,11 @@ inline.pedantic = merge$1({}, inline.normal, {
1327
1311
  endAst: /\*(?!\*)/g,
1328
1312
  endUnd: /_(?!_)/g
1329
1313
  },
1330
- link: edit$1(/^!?\[(label)\]\((.*?)\)/)
1331
- .replace('label', inline._label)
1314
+ link: edit(/^!?\[(label)\]\((.*?)\)/)
1315
+ .replace('label', inline$1._label)
1332
1316
  .getRegex(),
1333
- reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/)
1334
- .replace('label', inline._label)
1317
+ reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
1318
+ .replace('label', inline$1._label)
1335
1319
  .getRegex()
1336
1320
  });
1337
1321
 
@@ -1339,38 +1323,38 @@ inline.pedantic = merge$1({}, inline.normal, {
1339
1323
  * GFM Inline Grammar
1340
1324
  */
1341
1325
 
1342
- inline.gfm = merge$1({}, inline.normal, {
1343
- escape: edit$1(inline.escape).replace('])', '~|])').getRegex(),
1326
+ inline$1.gfm = merge$1({}, inline$1.normal, {
1327
+ escape: edit(inline$1.escape).replace('])', '~|])').getRegex(),
1344
1328
  _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
1345
1329
  url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
1346
1330
  _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
1347
1331
  del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
1348
- text: /^([`~]+|[^`~])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
1332
+ text: /^([`~]+|[^`~])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
1349
1333
  });
1350
1334
 
1351
- inline.gfm.url = edit$1(inline.gfm.url, 'i')
1352
- .replace('email', inline.gfm._extended_email)
1335
+ inline$1.gfm.url = edit(inline$1.gfm.url, 'i')
1336
+ .replace('email', inline$1.gfm._extended_email)
1353
1337
  .getRegex();
1354
1338
  /**
1355
1339
  * GFM + Line Breaks Inline Grammar
1356
1340
  */
1357
1341
 
1358
- inline.breaks = merge$1({}, inline.gfm, {
1359
- br: edit$1(inline.br).replace('{2,}', '*').getRegex(),
1360
- text: edit$1(inline.gfm.text)
1342
+ inline$1.breaks = merge$1({}, inline$1.gfm, {
1343
+ br: edit(inline$1.br).replace('{2,}', '*').getRegex(),
1344
+ text: edit(inline$1.gfm.text)
1361
1345
  .replace('\\b_', '\\b_| {2,}\\n')
1362
1346
  .replace(/\{2,\}/g, '*')
1363
1347
  .getRegex()
1364
1348
  });
1365
1349
 
1366
1350
  var rules = {
1367
- block,
1368
- inline
1351
+ block: block$1,
1352
+ inline: inline$1
1369
1353
  };
1370
1354
 
1371
- const { defaults: defaults$2 } = defaults;
1372
- const { block: block$1, inline: inline$1 } = rules;
1373
- const { repeatString: repeatString$1 } = helpers;
1355
+ const { defaults: defaults$3 } = defaults$5;
1356
+ const { block, inline } = rules;
1357
+ const { repeatString } = helpers;
1374
1358
 
1375
1359
  /**
1376
1360
  * smartypants text replacement
@@ -1420,25 +1404,25 @@ var Lexer_1 = class Lexer {
1420
1404
  constructor(options) {
1421
1405
  this.tokens = [];
1422
1406
  this.tokens.links = Object.create(null);
1423
- this.options = options || defaults$2;
1407
+ this.options = options || defaults$3;
1424
1408
  this.options.tokenizer = this.options.tokenizer || new Tokenizer_1();
1425
1409
  this.tokenizer = this.options.tokenizer;
1426
1410
  this.tokenizer.options = this.options;
1427
1411
 
1428
1412
  const rules = {
1429
- block: block$1.normal,
1430
- inline: inline$1.normal
1413
+ block: block.normal,
1414
+ inline: inline.normal
1431
1415
  };
1432
1416
 
1433
1417
  if (this.options.pedantic) {
1434
- rules.block = block$1.pedantic;
1435
- rules.inline = inline$1.pedantic;
1418
+ rules.block = block.pedantic;
1419
+ rules.inline = inline.pedantic;
1436
1420
  } else if (this.options.gfm) {
1437
- rules.block = block$1.gfm;
1421
+ rules.block = block.gfm;
1438
1422
  if (this.options.breaks) {
1439
- rules.inline = inline$1.breaks;
1423
+ rules.inline = inline.breaks;
1440
1424
  } else {
1441
- rules.inline = inline$1.gfm;
1425
+ rules.inline = inline.gfm;
1442
1426
  }
1443
1427
  }
1444
1428
  this.tokenizer.rules = rules;
@@ -1449,8 +1433,8 @@ var Lexer_1 = class Lexer {
1449
1433
  */
1450
1434
  static get rules() {
1451
1435
  return {
1452
- block: block$1,
1453
- inline: inline$1
1436
+ block,
1437
+ inline
1454
1438
  };
1455
1439
  }
1456
1440
 
@@ -1505,14 +1489,15 @@ var Lexer_1 = class Lexer {
1505
1489
  }
1506
1490
 
1507
1491
  // code
1508
- if (token = this.tokenizer.code(src, tokens)) {
1492
+ if (token = this.tokenizer.code(src)) {
1509
1493
  src = src.substring(token.raw.length);
1510
- if (token.type) {
1511
- tokens.push(token);
1512
- } else {
1513
- lastToken = tokens[tokens.length - 1];
1494
+ lastToken = tokens[tokens.length - 1];
1495
+ // An indented code block cannot interrupt a paragraph.
1496
+ if (lastToken && lastToken.type === 'paragraph') {
1514
1497
  lastToken.raw += '\n' + token.raw;
1515
1498
  lastToken.text += '\n' + token.text;
1499
+ } else {
1500
+ tokens.push(token);
1516
1501
  }
1517
1502
  continue;
1518
1503
  }
@@ -1605,14 +1590,14 @@ var Lexer_1 = class Lexer {
1605
1590
  }
1606
1591
 
1607
1592
  // text
1608
- if (token = this.tokenizer.text(src, tokens)) {
1593
+ if (token = this.tokenizer.text(src)) {
1609
1594
  src = src.substring(token.raw.length);
1610
- if (token.type) {
1611
- tokens.push(token);
1612
- } else {
1613
- lastToken = tokens[tokens.length - 1];
1595
+ lastToken = tokens[tokens.length - 1];
1596
+ if (lastToken && lastToken.type === 'text') {
1614
1597
  lastToken.raw += '\n' + token.raw;
1615
1598
  lastToken.text += '\n' + token.text;
1599
+ } else {
1600
+ tokens.push(token);
1616
1601
  }
1617
1602
  continue;
1618
1603
  }
@@ -1697,7 +1682,7 @@ var Lexer_1 = class Lexer {
1697
1682
  * Lexing/Compiling
1698
1683
  */
1699
1684
  inlineTokens(src, tokens = [], inLink = false, inRawBlock = false) {
1700
- let token;
1685
+ let token, lastToken;
1701
1686
 
1702
1687
  // String with links masked to avoid interference with em and strong
1703
1688
  let maskedSrc = src;
@@ -1710,14 +1695,19 @@ var Lexer_1 = class Lexer {
1710
1695
  if (links.length > 0) {
1711
1696
  while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
1712
1697
  if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
1713
- maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString$1('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
1698
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
1714
1699
  }
1715
1700
  }
1716
1701
  }
1717
1702
  }
1718
1703
  // Mask out other blocks
1719
1704
  while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
1720
- maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString$1('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1705
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1706
+ }
1707
+
1708
+ // Mask out escaped em & strong delimiters
1709
+ while ((match = this.tokenizer.rules.inline.escapedEmSt.exec(maskedSrc)) != null) {
1710
+ maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex);
1721
1711
  }
1722
1712
 
1723
1713
  while (src) {
@@ -1725,6 +1715,7 @@ var Lexer_1 = class Lexer {
1725
1715
  prevChar = '';
1726
1716
  }
1727
1717
  keepPrevChar = false;
1718
+
1728
1719
  // escape
1729
1720
  if (token = this.tokenizer.escape(src)) {
1730
1721
  src = src.substring(token.raw.length);
@@ -1737,7 +1728,13 @@ var Lexer_1 = class Lexer {
1737
1728
  src = src.substring(token.raw.length);
1738
1729
  inLink = token.inLink;
1739
1730
  inRawBlock = token.inRawBlock;
1740
- tokens.push(token);
1731
+ const lastToken = tokens[tokens.length - 1];
1732
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1733
+ lastToken.raw += token.raw;
1734
+ lastToken.text += token.text;
1735
+ } else {
1736
+ tokens.push(token);
1737
+ }
1741
1738
  continue;
1742
1739
  }
1743
1740
 
@@ -1754,23 +1751,21 @@ var Lexer_1 = class Lexer {
1754
1751
  // reflink, nolink
1755
1752
  if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1756
1753
  src = src.substring(token.raw.length);
1754
+ const lastToken = tokens[tokens.length - 1];
1757
1755
  if (token.type === 'link') {
1758
1756
  token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
1757
+ tokens.push(token);
1758
+ } else if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1759
+ lastToken.raw += token.raw;
1760
+ lastToken.text += token.text;
1761
+ } else {
1762
+ tokens.push(token);
1759
1763
  }
1760
- tokens.push(token);
1761
- continue;
1762
- }
1763
-
1764
- // strong
1765
- if (token = this.tokenizer.strong(src, maskedSrc, prevChar)) {
1766
- src = src.substring(token.raw.length);
1767
- token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1768
- tokens.push(token);
1769
1764
  continue;
1770
1765
  }
1771
1766
 
1772
- // em
1773
- if (token = this.tokenizer.em(src, maskedSrc, prevChar)) {
1767
+ // em & strong
1768
+ if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
1774
1769
  src = src.substring(token.raw.length);
1775
1770
  token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1776
1771
  tokens.push(token);
@@ -1816,9 +1811,17 @@ var Lexer_1 = class Lexer {
1816
1811
  // text
1817
1812
  if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) {
1818
1813
  src = src.substring(token.raw.length);
1819
- prevChar = token.raw.slice(-1);
1814
+ if (token.raw.slice(-1) !== '_') { // Track prevChar before string of ____ started
1815
+ prevChar = token.raw.slice(-1);
1816
+ }
1820
1817
  keepPrevChar = true;
1821
- tokens.push(token);
1818
+ lastToken = tokens[tokens.length - 1];
1819
+ if (lastToken && lastToken.type === 'text') {
1820
+ lastToken.raw += token.raw;
1821
+ lastToken.text += token.text;
1822
+ } else {
1823
+ tokens.push(token);
1824
+ }
1822
1825
  continue;
1823
1826
  }
1824
1827
 
@@ -1837,10 +1840,10 @@ var Lexer_1 = class Lexer {
1837
1840
  }
1838
1841
  };
1839
1842
 
1840
- const { defaults: defaults$3 } = defaults;
1843
+ const { defaults: defaults$2 } = defaults$5;
1841
1844
  const {
1842
- cleanUrl: cleanUrl$1,
1843
- escape: escape$2
1845
+ cleanUrl,
1846
+ escape: escape$1
1844
1847
  } = helpers;
1845
1848
 
1846
1849
  /**
@@ -1848,7 +1851,7 @@ const {
1848
1851
  */
1849
1852
  var Renderer_1 = class Renderer {
1850
1853
  constructor(options) {
1851
- this.options = options || defaults$3;
1854
+ this.options = options || defaults$2;
1852
1855
  }
1853
1856
 
1854
1857
  code(code, infostring, escaped) {
@@ -1865,15 +1868,15 @@ var Renderer_1 = class Renderer {
1865
1868
 
1866
1869
  if (!lang) {
1867
1870
  return '<pre><code>'
1868
- + (escaped ? code : escape$2(code, true))
1871
+ + (escaped ? code : escape$1(code, true))
1869
1872
  + '</code></pre>\n';
1870
1873
  }
1871
1874
 
1872
1875
  return '<pre><code class="'
1873
1876
  + this.options.langPrefix
1874
- + escape$2(lang, true)
1877
+ + escape$1(lang, true)
1875
1878
  + '">'
1876
- + (escaped ? code : escape$2(code, true))
1879
+ + (escaped ? code : escape$1(code, true))
1877
1880
  + '</code></pre>\n';
1878
1881
  }
1879
1882
 
@@ -1973,11 +1976,11 @@ var Renderer_1 = class Renderer {
1973
1976
  }
1974
1977
 
1975
1978
  link(href, title, text) {
1976
- href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
1979
+ href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1977
1980
  if (href === null) {
1978
1981
  return text;
1979
1982
  }
1980
- let out = '<a href="' + escape$2(href) + '"';
1983
+ let out = '<a href="' + escape$1(href) + '"';
1981
1984
  if (title) {
1982
1985
  out += ' title="' + title + '"';
1983
1986
  }
@@ -1986,7 +1989,7 @@ var Renderer_1 = class Renderer {
1986
1989
  }
1987
1990
 
1988
1991
  image(href, title, text) {
1989
- href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
1992
+ href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1990
1993
  if (href === null) {
1991
1994
  return text;
1992
1995
  }
@@ -2097,9 +2100,9 @@ var Slugger_1 = class Slugger {
2097
2100
  }
2098
2101
  };
2099
2102
 
2100
- const { defaults: defaults$4 } = defaults;
2103
+ const { defaults: defaults$1 } = defaults$5;
2101
2104
  const {
2102
- unescape: unescape$1
2105
+ unescape
2103
2106
  } = helpers;
2104
2107
 
2105
2108
  /**
@@ -2107,7 +2110,7 @@ const {
2107
2110
  */
2108
2111
  var Parser_1 = class Parser {
2109
2112
  constructor(options) {
2110
- this.options = options || defaults$4;
2113
+ this.options = options || defaults$1;
2111
2114
  this.options.renderer = this.options.renderer || new Renderer_1();
2112
2115
  this.renderer = this.options.renderer;
2113
2116
  this.renderer.options = this.options;
@@ -2170,7 +2173,7 @@ var Parser_1 = class Parser {
2170
2173
  out += this.renderer.heading(
2171
2174
  this.parseInline(token.tokens),
2172
2175
  token.depth,
2173
- unescape$1(this.parseInline(token.tokens, this.textRenderer)),
2176
+ unescape(this.parseInline(token.tokens, this.textRenderer)),
2174
2177
  this.slugger);
2175
2178
  continue;
2176
2179
  }
@@ -2359,15 +2362,15 @@ var Parser_1 = class Parser {
2359
2362
  };
2360
2363
 
2361
2364
  const {
2362
- merge: merge$2,
2363
- checkSanitizeDeprecation: checkSanitizeDeprecation$1,
2364
- escape: escape$3
2365
+ merge,
2366
+ checkSanitizeDeprecation,
2367
+ escape
2365
2368
  } = helpers;
2366
2369
  const {
2367
2370
  getDefaults,
2368
2371
  changeDefaults,
2369
- defaults: defaults$5
2370
- } = defaults;
2372
+ defaults
2373
+ } = defaults$5;
2371
2374
 
2372
2375
  /**
2373
2376
  * Marked
@@ -2387,8 +2390,8 @@ function marked(src, opt, callback) {
2387
2390
  opt = null;
2388
2391
  }
2389
2392
 
2390
- opt = merge$2({}, marked.defaults, opt || {});
2391
- checkSanitizeDeprecation$1(opt);
2393
+ opt = merge({}, marked.defaults, opt || {});
2394
+ checkSanitizeDeprecation(opt);
2392
2395
 
2393
2396
  if (callback) {
2394
2397
  const highlight = opt.highlight;
@@ -2466,7 +2469,7 @@ function marked(src, opt, callback) {
2466
2469
  e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2467
2470
  if (opt.silent) {
2468
2471
  return '<p>An error occurred:</p><pre>'
2469
- + escape$3(e.message + '', true)
2472
+ + escape(e.message + '', true)
2470
2473
  + '</pre>';
2471
2474
  }
2472
2475
  throw e;
@@ -2479,21 +2482,21 @@ function marked(src, opt, callback) {
2479
2482
 
2480
2483
  marked.options =
2481
2484
  marked.setOptions = function(opt) {
2482
- merge$2(marked.defaults, opt);
2485
+ merge(marked.defaults, opt);
2483
2486
  changeDefaults(marked.defaults);
2484
2487
  return marked;
2485
2488
  };
2486
2489
 
2487
2490
  marked.getDefaults = getDefaults;
2488
2491
 
2489
- marked.defaults = defaults$5;
2492
+ marked.defaults = defaults;
2490
2493
 
2491
2494
  /**
2492
2495
  * Use Extension
2493
2496
  */
2494
2497
 
2495
2498
  marked.use = function(extension) {
2496
- const opts = merge$2({}, extension);
2499
+ const opts = merge({}, extension);
2497
2500
  if (extension.renderer) {
2498
2501
  const renderer = marked.defaults.renderer || new Renderer_1();
2499
2502
  for (const prop in extension.renderer) {
@@ -2579,8 +2582,8 @@ marked.parseInline = function(src, opt) {
2579
2582
  + Object.prototype.toString.call(src) + ', string expected');
2580
2583
  }
2581
2584
 
2582
- opt = merge$2({}, marked.defaults, opt || {});
2583
- checkSanitizeDeprecation$1(opt);
2585
+ opt = merge({}, marked.defaults, opt || {});
2586
+ checkSanitizeDeprecation(opt);
2584
2587
 
2585
2588
  try {
2586
2589
  const tokens = Lexer_1.lexInline(src, opt);
@@ -2592,7 +2595,7 @@ marked.parseInline = function(src, opt) {
2592
2595
  e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2593
2596
  if (opt.silent) {
2594
2597
  return '<p>An error occurred:</p><pre>'
2595
- + escape$3(e.message + '', true)
2598
+ + escape(e.message + '', true)
2596
2599
  + '</pre>';
2597
2600
  }
2598
2601
  throw e;