marked 2.1.0 → 3.0.0

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
@@ -208,6 +208,10 @@ function splitCells$1(tableRow, count) {
208
208
  cells = row.split(/ \|/);
209
209
  let i = 0;
210
210
 
211
+ // First/last cell in a row cannot be empty if it has no leading/trailing pipe
212
+ if (!cells[0].trim()) { cells.shift(); }
213
+ if (!cells[cells.length - 1].trim()) { cells.pop(); }
214
+
211
215
  if (cells.length > count) {
212
216
  cells.splice(count);
213
217
  } else {
@@ -315,18 +319,20 @@ const {
315
319
  findClosingBracket
316
320
  } = helpers;
317
321
 
318
- function outputLink(cap, link, raw) {
322
+ function outputLink(cap, link, raw, lexer) {
319
323
  const href = link.href;
320
324
  const title = link.title ? escape$2(link.title) : null;
321
325
  const text = cap[1].replace(/\\([\[\]])/g, '$1');
322
326
 
323
327
  if (cap[0].charAt(0) !== '!') {
328
+ lexer.state.inLink = true;
324
329
  return {
325
330
  type: 'link',
326
331
  raw,
327
332
  href,
328
333
  title,
329
- text
334
+ text,
335
+ tokens: lexer.inlineTokens(text, [])
330
336
  };
331
337
  } else {
332
338
  return {
@@ -434,48 +440,15 @@ var Tokenizer_1 = class Tokenizer {
434
440
  }
435
441
  }
436
442
 
437
- return {
443
+ const token = {
438
444
  type: 'heading',
439
445
  raw: cap[0],
440
446
  depth: cap[1].length,
441
- text: text
447
+ text: text,
448
+ tokens: []
442
449
  };
443
- }
444
- }
445
-
446
- nptable(src) {
447
- const cap = this.rules.block.nptable.exec(src);
448
- if (cap) {
449
- const item = {
450
- type: 'table',
451
- header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
452
- align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
453
- cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [],
454
- raw: cap[0]
455
- };
456
-
457
- if (item.header.length === item.align.length) {
458
- let l = item.align.length;
459
- let i;
460
- for (i = 0; i < l; i++) {
461
- if (/^ *-+: *$/.test(item.align[i])) {
462
- item.align[i] = 'right';
463
- } else if (/^ *:-+: *$/.test(item.align[i])) {
464
- item.align[i] = 'center';
465
- } else if (/^ *:-+ *$/.test(item.align[i])) {
466
- item.align[i] = 'left';
467
- } else {
468
- item.align[i] = null;
469
- }
470
- }
471
-
472
- l = item.cells.length;
473
- for (i = 0; i < l; i++) {
474
- item.cells[i] = splitCells(item.cells[i], item.header.length);
475
- }
476
-
477
- return item;
478
- }
450
+ this.lexer.inline(token.text, token.tokens);
451
+ return token;
479
452
  }
480
453
  }
481
454
 
@@ -497,138 +470,155 @@ var Tokenizer_1 = class Tokenizer {
497
470
  return {
498
471
  type: 'blockquote',
499
472
  raw: cap[0],
473
+ tokens: this.lexer.blockTokens(text, []),
500
474
  text
501
475
  };
502
476
  }
503
477
  }
504
478
 
505
479
  list(src) {
506
- const cap = this.rules.block.list.exec(src);
480
+ let cap = this.rules.block.list.exec(src);
507
481
  if (cap) {
508
- let raw = cap[0];
509
- const bull = cap[2];
482
+ let raw, istask, ischecked, indent, i, blankLine, endsWithBlankLine,
483
+ line, lines, itemContents;
484
+
485
+ let bull = cap[1].trim();
510
486
  const isordered = bull.length > 1;
511
487
 
512
488
  const list = {
513
489
  type: 'list',
514
- raw,
490
+ raw: '',
515
491
  ordered: isordered,
516
492
  start: isordered ? +bull.slice(0, -1) : '',
517
493
  loose: false,
518
494
  items: []
519
495
  };
520
496
 
521
- // Get each top-level item.
522
- const itemMatch = cap[0].match(this.rules.block.item);
523
-
524
- let next = false,
525
- item,
526
- space,
527
- bcurr,
528
- bnext,
529
- addBack,
530
- loose,
531
- istask,
532
- ischecked,
533
- endMatch;
534
-
535
- let l = itemMatch.length;
536
- bcurr = this.rules.block.listItemStart.exec(itemMatch[0]);
537
- for (let i = 0; i < l; i++) {
538
- item = itemMatch[i];
539
- raw = item;
540
-
541
- if (!this.options.pedantic) {
542
- // Determine if current item contains the end of the list
543
- endMatch = item.match(new RegExp('\\n\\s*\\n {0,' + (bcurr[0].length - 1) + '}\\S'));
544
- if (endMatch) {
545
- addBack = item.length - endMatch.index + itemMatch.slice(i + 1).join('\n').length;
546
- list.raw = list.raw.substring(0, list.raw.length - addBack);
547
-
548
- item = item.substring(0, endMatch.index);
549
- raw = item;
550
- l = i + 1;
551
- }
497
+ bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
498
+
499
+ if (this.options.pedantic) {
500
+ bull = isordered ? bull : '[*+-]';
501
+ }
502
+
503
+ // Get next list item
504
+ const itemRegex = new RegExp(`^( {0,3}${bull})((?: [^\\n]*| *)(?:\\n[^\\n]*)*(?:\\n|$))`);
505
+
506
+ // Get each top-level item
507
+ while (src) {
508
+ if (this.rules.block.hr.test(src)) { // End list if we encounter an HR (possibly move into itemRegex?)
509
+ break;
552
510
  }
553
511
 
554
- // Determine whether the next list item belongs here.
555
- // Backpedal if it does not belong in this list.
556
- if (i !== l - 1) {
557
- bnext = this.rules.block.listItemStart.exec(itemMatch[i + 1]);
558
- if (
559
- !this.options.pedantic
560
- ? bnext[1].length >= bcurr[0].length || bnext[1].length > 3
561
- : bnext[1].length > bcurr[1].length
562
- ) {
563
- // nested list or continuation
564
- itemMatch.splice(i, 2, itemMatch[i] + (!this.options.pedantic && bnext[1].length < bcurr[0].length && !itemMatch[i].match(/\n$/) ? '' : '\n') + itemMatch[i + 1]);
565
- i--;
566
- l--;
567
- continue;
568
- } else if (
569
- // different bullet style
570
- !this.options.pedantic || this.options.smartLists
571
- ? bnext[2][bnext[2].length - 1] !== bull[bull.length - 1]
572
- : isordered === (bnext[2].length === 1)
573
- ) {
574
- addBack = itemMatch.slice(i + 1).join('\n').length;
575
- list.raw = list.raw.substring(0, list.raw.length - addBack);
576
- i = l - 1;
577
- }
578
- bcurr = bnext;
512
+ if (!(cap = itemRegex.exec(src))) {
513
+ break;
579
514
  }
580
515
 
581
- // Remove the list item's bullet
582
- // so it is seen as the next token.
583
- space = item.length;
584
- item = item.replace(/^ *([*+-]|\d+[.)]) ?/, '');
516
+ lines = cap[2].split('\n');
585
517
 
586
- // Outdent whatever the
587
- // list item contains. Hacky.
588
- if (~item.indexOf('\n ')) {
589
- space -= item.length;
590
- item = !this.options.pedantic
591
- ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
592
- : item.replace(/^ {1,4}/gm, '');
518
+ if (this.options.pedantic) {
519
+ indent = 2;
520
+ itemContents = lines[0].trimLeft();
521
+ } else {
522
+ indent = cap[2].search(/[^ ]/); // Find first non-space char
523
+ indent = cap[1].length + (indent > 4 ? 1 : indent); // intented code blocks after 4 spaces; indent is always 1
524
+ itemContents = lines[0].slice(indent - cap[1].length);
593
525
  }
594
526
 
595
- // trim item newlines at end
596
- item = rtrim(item, '\n');
597
- if (i !== l - 1) {
598
- raw = raw + '\n';
527
+ blankLine = false;
528
+ raw = cap[0];
529
+
530
+ if (!lines[0] && /^ *$/.test(lines[1])) { // items begin with at most one blank line
531
+ raw = cap[1] + lines.slice(0, 2).join('\n') + '\n';
532
+ list.loose = true;
533
+ lines = [];
599
534
  }
600
535
 
601
- // Determine whether item is loose or not.
602
- // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
603
- // for discount behavior.
604
- loose = next || /\n\n(?!\s*$)/.test(raw);
605
- if (i !== l - 1) {
606
- next = raw.slice(-2) === '\n\n';
607
- if (!loose) loose = next;
536
+ const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])`);
537
+
538
+ for (i = 1; i < lines.length; i++) {
539
+ line = lines[i];
540
+
541
+ if (this.options.pedantic) { // Re-align to follow commonmark nesting rules
542
+ line = line.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
543
+ }
544
+
545
+ // End list item if found start of new bullet
546
+ if (nextBulletRegex.test(line)) {
547
+ raw = cap[1] + lines.slice(0, i).join('\n') + '\n';
548
+ break;
549
+ }
550
+
551
+ // Until we encounter a blank line, item contents do not need indentation
552
+ if (!blankLine) {
553
+ if (!line.trim()) { // Check if current line is empty
554
+ blankLine = true;
555
+ }
556
+
557
+ // Dedent if possible
558
+ if (line.search(/[^ ]/) >= indent) {
559
+ itemContents += '\n' + line.slice(indent);
560
+ } else {
561
+ itemContents += '\n' + line;
562
+ }
563
+ continue;
564
+ }
565
+
566
+ // Dedent this line
567
+ if (line.search(/[^ ]/) >= indent || !line.trim()) {
568
+ itemContents += '\n' + line.slice(indent);
569
+ continue;
570
+ } else { // Line was not properly indented; end of this item
571
+ raw = cap[1] + lines.slice(0, i).join('\n') + '\n';
572
+ break;
573
+ }
608
574
  }
609
575
 
610
- if (loose) {
611
- list.loose = true;
576
+ if (!list.loose) {
577
+ // If the previous item ended with a blank line, the list is loose
578
+ if (endsWithBlankLine) {
579
+ list.loose = true;
580
+ } else if (/\n *\n *$/.test(raw)) {
581
+ endsWithBlankLine = true;
582
+ }
612
583
  }
613
584
 
614
585
  // Check for task list items
615
586
  if (this.options.gfm) {
616
- istask = /^\[[ xX]\] /.test(item);
617
- ischecked = undefined;
587
+ istask = /^\[[ xX]\] /.exec(itemContents);
618
588
  if (istask) {
619
- ischecked = item[1] !== ' ';
620
- item = item.replace(/^\[[ xX]\] +/, '');
589
+ ischecked = istask[0] !== '[ ] ';
590
+ itemContents = itemContents.replace(/^\[[ xX]\] +/, '');
621
591
  }
622
592
  }
623
593
 
624
594
  list.items.push({
625
595
  type: 'list_item',
626
- raw,
627
- task: istask,
596
+ raw: raw,
597
+ task: !!istask,
628
598
  checked: ischecked,
629
- loose: loose,
630
- text: item
599
+ loose: false,
600
+ text: itemContents
631
601
  });
602
+
603
+ list.raw += raw;
604
+ src = src.slice(raw.length);
605
+ }
606
+
607
+ // Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
608
+ list.items[list.items.length - 1].raw = raw.trimRight();
609
+ list.items[list.items.length - 1].text = itemContents.trimRight();
610
+ list.raw = list.raw.trimRight();
611
+
612
+ const l = list.items.length;
613
+
614
+ // Item child tokens handled here at end because we needed to have the final item to trim it first
615
+ for (i = 0; i < l; i++) {
616
+ this.lexer.state.top = false;
617
+ list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
618
+ if (list.items[i].tokens.some(t => t.type === 'space')) {
619
+ list.loose = true;
620
+ list.items[i].loose = true;
621
+ }
632
622
  }
633
623
 
634
624
  return list;
@@ -638,15 +628,20 @@ var Tokenizer_1 = class Tokenizer {
638
628
  html(src) {
639
629
  const cap = this.rules.block.html.exec(src);
640
630
  if (cap) {
641
- return {
642
- type: this.options.sanitize
643
- ? 'paragraph'
644
- : 'html',
631
+ const token = {
632
+ type: 'html',
645
633
  raw: cap[0],
646
634
  pre: !this.options.sanitizer
647
635
  && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
648
- text: this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$2(cap[0])) : cap[0]
636
+ text: cap[0]
649
637
  };
638
+ if (this.options.sanitize) {
639
+ token.type = 'paragraph';
640
+ token.text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$2(cap[0]);
641
+ token.tokens = [];
642
+ this.lexer.inline(token.text, token.tokens);
643
+ }
644
+ return token;
650
645
  }
651
646
  }
652
647
 
@@ -670,16 +665,16 @@ var Tokenizer_1 = class Tokenizer {
670
665
  if (cap) {
671
666
  const item = {
672
667
  type: 'table',
673
- header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
668
+ header: splitCells(cap[1]).map(c => { return { text: c }; }),
674
669
  align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
675
- cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
670
+ rows: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
676
671
  };
677
672
 
678
673
  if (item.header.length === item.align.length) {
679
674
  item.raw = cap[0];
680
675
 
681
676
  let l = item.align.length;
682
- let i;
677
+ let i, j, k, row;
683
678
  for (i = 0; i < l; i++) {
684
679
  if (/^ *-+: *$/.test(item.align[i])) {
685
680
  item.align[i] = 'right';
@@ -692,11 +687,28 @@ var Tokenizer_1 = class Tokenizer {
692
687
  }
693
688
  }
694
689
 
695
- l = item.cells.length;
690
+ l = item.rows.length;
696
691
  for (i = 0; i < l; i++) {
697
- item.cells[i] = splitCells(
698
- item.cells[i].replace(/^ *\| *| *\| *$/g, ''),
699
- item.header.length);
692
+ item.rows[i] = splitCells(item.rows[i], item.header.length).map(c => { return { text: c }; });
693
+ }
694
+
695
+ // parse child tokens inside headers and cells
696
+
697
+ // header child tokens
698
+ l = item.header.length;
699
+ for (j = 0; j < l; j++) {
700
+ item.header[j].tokens = [];
701
+ this.lexer.inlineTokens(item.header[j].text, item.header[j].tokens);
702
+ }
703
+
704
+ // cell child tokens
705
+ l = item.rows.length;
706
+ for (j = 0; j < l; j++) {
707
+ row = item.rows[j];
708
+ for (k = 0; k < row.length; k++) {
709
+ row[k].tokens = [];
710
+ this.lexer.inlineTokens(row[k].text, row[k].tokens);
711
+ }
700
712
  }
701
713
 
702
714
  return item;
@@ -707,36 +719,45 @@ var Tokenizer_1 = class Tokenizer {
707
719
  lheading(src) {
708
720
  const cap = this.rules.block.lheading.exec(src);
709
721
  if (cap) {
710
- return {
722
+ const token = {
711
723
  type: 'heading',
712
724
  raw: cap[0],
713
725
  depth: cap[2].charAt(0) === '=' ? 1 : 2,
714
- text: cap[1]
726
+ text: cap[1],
727
+ tokens: []
715
728
  };
729
+ this.lexer.inline(token.text, token.tokens);
730
+ return token;
716
731
  }
717
732
  }
718
733
 
719
734
  paragraph(src) {
720
735
  const cap = this.rules.block.paragraph.exec(src);
721
736
  if (cap) {
722
- return {
737
+ const token = {
723
738
  type: 'paragraph',
724
739
  raw: cap[0],
725
740
  text: cap[1].charAt(cap[1].length - 1) === '\n'
726
741
  ? cap[1].slice(0, -1)
727
- : cap[1]
742
+ : cap[1],
743
+ tokens: []
728
744
  };
745
+ this.lexer.inline(token.text, token.tokens);
746
+ return token;
729
747
  }
730
748
  }
731
749
 
732
750
  text(src) {
733
751
  const cap = this.rules.block.text.exec(src);
734
752
  if (cap) {
735
- return {
753
+ const token = {
736
754
  type: 'text',
737
755
  raw: cap[0],
738
- text: cap[0]
756
+ text: cap[0],
757
+ tokens: []
739
758
  };
759
+ this.lexer.inline(token.text, token.tokens);
760
+ return token;
740
761
  }
741
762
  }
742
763
 
@@ -751,18 +772,18 @@ var Tokenizer_1 = class Tokenizer {
751
772
  }
752
773
  }
753
774
 
754
- tag(src, inLink, inRawBlock) {
775
+ tag(src) {
755
776
  const cap = this.rules.inline.tag.exec(src);
756
777
  if (cap) {
757
- if (!inLink && /^<a /i.test(cap[0])) {
758
- inLink = true;
759
- } else if (inLink && /^<\/a>/i.test(cap[0])) {
760
- inLink = false;
778
+ if (!this.lexer.state.inLink && /^<a /i.test(cap[0])) {
779
+ this.lexer.state.inLink = true;
780
+ } else if (this.lexer.state.inLink && /^<\/a>/i.test(cap[0])) {
781
+ this.lexer.state.inLink = false;
761
782
  }
762
- if (!inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
763
- inRawBlock = true;
764
- } else if (inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
765
- inRawBlock = false;
783
+ if (!this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
784
+ this.lexer.state.inRawBlock = true;
785
+ } else if (this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
786
+ this.lexer.state.inRawBlock = false;
766
787
  }
767
788
 
768
789
  return {
@@ -770,8 +791,8 @@ var Tokenizer_1 = class Tokenizer {
770
791
  ? 'text'
771
792
  : 'html',
772
793
  raw: cap[0],
773
- inLink,
774
- inRawBlock,
794
+ inLink: this.lexer.state.inLink,
795
+ inRawBlock: this.lexer.state.inRawBlock,
775
796
  text: this.options.sanitize
776
797
  ? (this.options.sanitizer
777
798
  ? this.options.sanitizer(cap[0])
@@ -833,7 +854,7 @@ var Tokenizer_1 = class Tokenizer {
833
854
  return outputLink(cap, {
834
855
  href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
835
856
  title: title ? title.replace(this.rules.inline._escapes, '$1') : title
836
- }, cap[0]);
857
+ }, cap[0], this.lexer);
837
858
  }
838
859
  }
839
860
 
@@ -851,7 +872,7 @@ var Tokenizer_1 = class Tokenizer {
851
872
  text
852
873
  };
853
874
  }
854
- return outputLink(cap, link, cap[0]);
875
+ return outputLink(cap, link, cap[0], this.lexer);
855
876
  }
856
877
  }
857
878
 
@@ -900,18 +921,22 @@ var Tokenizer_1 = class Tokenizer {
900
921
 
901
922
  // Create `em` if smallest delimiter has odd char count. *a***
902
923
  if (Math.min(lLength, rLength) % 2) {
924
+ const text = src.slice(1, lLength + match.index + rLength);
903
925
  return {
904
926
  type: 'em',
905
927
  raw: src.slice(0, lLength + match.index + rLength + 1),
906
- text: src.slice(1, lLength + match.index + rLength)
928
+ text,
929
+ tokens: this.lexer.inlineTokens(text, [])
907
930
  };
908
931
  }
909
932
 
910
933
  // Create 'strong' if smallest delimiter has even char count. **a***
934
+ const text = src.slice(2, lLength + match.index + rLength - 1);
911
935
  return {
912
936
  type: 'strong',
913
937
  raw: src.slice(0, lLength + match.index + rLength + 1),
914
- text: src.slice(2, lLength + match.index + rLength - 1)
938
+ text,
939
+ tokens: this.lexer.inlineTokens(text, [])
915
940
  };
916
941
  }
917
942
  }
@@ -951,7 +976,8 @@ var Tokenizer_1 = class Tokenizer {
951
976
  return {
952
977
  type: 'del',
953
978
  raw: cap[0],
954
- text: cap[2]
979
+ text: cap[2],
980
+ tokens: this.lexer.inlineTokens(cap[2], [])
955
981
  };
956
982
  }
957
983
  }
@@ -1021,11 +1047,11 @@ var Tokenizer_1 = class Tokenizer {
1021
1047
  }
1022
1048
  }
1023
1049
 
1024
- inlineText(src, inRawBlock, smartypants) {
1050
+ inlineText(src, smartypants) {
1025
1051
  const cap = this.rules.inline.text.exec(src);
1026
1052
  if (cap) {
1027
1053
  let text;
1028
- if (inRawBlock) {
1054
+ if (this.lexer.state.inRawBlock) {
1029
1055
  text = this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$2(cap[0])) : cap[0];
1030
1056
  } else {
1031
1057
  text = escape$2(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
@@ -1051,23 +1077,22 @@ const {
1051
1077
  const block$1 = {
1052
1078
  newline: /^(?: *(?:\n|$))+/,
1053
1079
  code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
1054
- fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
1080
+ fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
1055
1081
  hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
1056
1082
  heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
1057
1083
  blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
1058
- list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?! {0,3}bull )\n*|\s*$)/,
1084
+ list: /^( {0,3}bull)( [^\n]+?)?(?:\n|$)/,
1059
1085
  html: '^ {0,3}(?:' // optional indentation
1060
- + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
1086
+ + '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
1061
1087
  + '|comment[^\\n]*(\\n+|$)' // (2)
1062
1088
  + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
1063
1089
  + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
1064
1090
  + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
1065
1091
  + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (6)
1066
- + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
1067
- + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
1092
+ + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
1093
+ + '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
1068
1094
  + ')',
1069
1095
  def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
1070
- nptable: noopTest,
1071
1096
  table: noopTest,
1072
1097
  lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
1073
1098
  // regex template, placeholders will be replaced according to different paragraph
@@ -1084,11 +1109,6 @@ block$1.def = edit(block$1.def)
1084
1109
  .getRegex();
1085
1110
 
1086
1111
  block$1.bullet = /(?:[*+-]|\d{1,9}[.)])/;
1087
- block$1.item = /^( *)(bull) ?[^\n]*(?:\n(?! *bull ?)[^\n]*)*/;
1088
- block$1.item = edit(block$1.item, 'gm')
1089
- .replace(/bull/g, block$1.bullet)
1090
- .getRegex();
1091
-
1092
1112
  block$1.listItemStart = edit(/^( *)(bull) */)
1093
1113
  .replace('bull', block$1.bullet)
1094
1114
  .getRegex();
@@ -1119,7 +1139,7 @@ block$1.paragraph = edit(block$1._paragraph)
1119
1139
  .replace('blockquote', ' {0,3}>')
1120
1140
  .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1121
1141
  .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1122
- .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
1142
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1123
1143
  .replace('tag', block$1._tag) // pars can be interrupted by type (6) html blocks
1124
1144
  .getRegex();
1125
1145
 
@@ -1138,25 +1158,11 @@ block$1.normal = merge$1({}, block$1);
1138
1158
  */
1139
1159
 
1140
1160
  block$1.gfm = merge$1({}, block$1.normal, {
1141
- nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
1142
- + ' {0,3}([-:]+ *\\|[-| :]*)' // Align
1143
- + '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)', // Cells
1144
- table: '^ *\\|(.+)\\n' // Header
1145
- + ' {0,3}\\|?( *[-:]+[-| :]*)' // Align
1161
+ table: '^ *([^\\n ].*\\|.*)\\n' // Header
1162
+ + ' {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)\\|?' // Align
1146
1163
  + '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
1147
1164
  });
1148
1165
 
1149
- block$1.gfm.nptable = edit(block$1.gfm.nptable)
1150
- .replace('hr', block$1.hr)
1151
- .replace('heading', ' {0,3}#{1,6} ')
1152
- .replace('blockquote', ' {0,3}>')
1153
- .replace('code', ' {4}[^\\n]')
1154
- .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1155
- .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1156
- .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
1157
- .replace('tag', block$1._tag) // tables can be interrupted by type (6) html blocks
1158
- .getRegex();
1159
-
1160
1166
  block$1.gfm.table = edit(block$1.gfm.table)
1161
1167
  .replace('hr', block$1.hr)
1162
1168
  .replace('heading', ' {0,3}#{1,6} ')
@@ -1164,7 +1170,7 @@ block$1.gfm.table = edit(block$1.gfm.table)
1164
1170
  .replace('code', ' {4}[^\\n]')
1165
1171
  .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1166
1172
  .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1167
- .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
1173
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1168
1174
  .replace('tag', block$1._tag) // tables can be interrupted by type (6) html blocks
1169
1175
  .getRegex();
1170
1176
 
@@ -1407,6 +1413,13 @@ var Lexer_1 = class Lexer {
1407
1413
  this.options.tokenizer = this.options.tokenizer || new Tokenizer$1();
1408
1414
  this.tokenizer = this.options.tokenizer;
1409
1415
  this.tokenizer.options = this.options;
1416
+ this.tokenizer.lexer = this;
1417
+ this.inlineQueue = [];
1418
+ this.state = {
1419
+ inLink: false,
1420
+ inRawBlock: false,
1421
+ top: true
1422
+ };
1410
1423
 
1411
1424
  const rules = {
1412
1425
  block: block.normal,
@@ -1461,9 +1474,12 @@ var Lexer_1 = class Lexer {
1461
1474
  .replace(/\r\n|\r/g, '\n')
1462
1475
  .replace(/\t/g, ' ');
1463
1476
 
1464
- this.blockTokens(src, this.tokens, true);
1477
+ this.blockTokens(src, this.tokens);
1465
1478
 
1466
- this.inline(this.tokens);
1479
+ let next;
1480
+ while (next = this.inlineQueue.shift()) {
1481
+ this.inlineTokens(next.src, next.tokens);
1482
+ }
1467
1483
 
1468
1484
  return this.tokens;
1469
1485
  }
@@ -1471,16 +1487,17 @@ var Lexer_1 = class Lexer {
1471
1487
  /**
1472
1488
  * Lexing
1473
1489
  */
1474
- blockTokens(src, tokens = [], top = true) {
1490
+ blockTokens(src, tokens = []) {
1475
1491
  if (this.options.pedantic) {
1476
1492
  src = src.replace(/^ +$/gm, '');
1477
1493
  }
1478
- let token, i, l, lastToken, cutSrc, lastParagraphClipped;
1494
+ let token, lastToken, cutSrc, lastParagraphClipped;
1479
1495
 
1480
1496
  while (src) {
1481
- if (this.options?.extensions?.block
1497
+ if (this.options.extensions
1498
+ && this.options.extensions.block
1482
1499
  && this.options.extensions.block.some((extTokenizer) => {
1483
- if (token = extTokenizer.call(this, src, tokens)) {
1500
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1484
1501
  src = src.substring(token.raw.length);
1485
1502
  tokens.push(token);
1486
1503
  return true;
@@ -1504,9 +1521,10 @@ var Lexer_1 = class Lexer {
1504
1521
  src = src.substring(token.raw.length);
1505
1522
  lastToken = tokens[tokens.length - 1];
1506
1523
  // An indented code block cannot interrupt a paragraph.
1507
- if (lastToken && lastToken.type === 'paragraph') {
1524
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1508
1525
  lastToken.raw += '\n' + token.raw;
1509
1526
  lastToken.text += '\n' + token.text;
1527
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1510
1528
  } else {
1511
1529
  tokens.push(token);
1512
1530
  }
@@ -1527,13 +1545,6 @@ var Lexer_1 = class Lexer {
1527
1545
  continue;
1528
1546
  }
1529
1547
 
1530
- // table no leading pipe (gfm)
1531
- if (token = this.tokenizer.nptable(src)) {
1532
- src = src.substring(token.raw.length);
1533
- tokens.push(token);
1534
- continue;
1535
- }
1536
-
1537
1548
  // hr
1538
1549
  if (token = this.tokenizer.hr(src)) {
1539
1550
  src = src.substring(token.raw.length);
@@ -1544,7 +1555,6 @@ var Lexer_1 = class Lexer {
1544
1555
  // blockquote
1545
1556
  if (token = this.tokenizer.blockquote(src)) {
1546
1557
  src = src.substring(token.raw.length);
1547
- token.tokens = this.blockTokens(token.text, [], top);
1548
1558
  tokens.push(token);
1549
1559
  continue;
1550
1560
  }
@@ -1552,10 +1562,6 @@ var Lexer_1 = class Lexer {
1552
1562
  // list
1553
1563
  if (token = this.tokenizer.list(src)) {
1554
1564
  src = src.substring(token.raw.length);
1555
- l = token.items.length;
1556
- for (i = 0; i < l; i++) {
1557
- token.items[i].tokens = this.blockTokens(token.items[i].text, [], false);
1558
- }
1559
1565
  tokens.push(token);
1560
1566
  continue;
1561
1567
  }
@@ -1568,9 +1574,14 @@ var Lexer_1 = class Lexer {
1568
1574
  }
1569
1575
 
1570
1576
  // def
1571
- if (top && (token = this.tokenizer.def(src))) {
1577
+ if (token = this.tokenizer.def(src)) {
1572
1578
  src = src.substring(token.raw.length);
1573
- if (!this.tokens.links[token.tag]) {
1579
+ lastToken = tokens[tokens.length - 1];
1580
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1581
+ lastToken.raw += '\n' + token.raw;
1582
+ lastToken.text += '\n' + token.raw;
1583
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1584
+ } else if (!this.tokens.links[token.tag]) {
1574
1585
  this.tokens.links[token.tag] = {
1575
1586
  href: token.href,
1576
1587
  title: token.title
@@ -1596,23 +1607,25 @@ var Lexer_1 = class Lexer {
1596
1607
  // top-level paragraph
1597
1608
  // prevent paragraph consuming extensions by clipping 'src' to extension start
1598
1609
  cutSrc = src;
1599
- if (this.options.extensions?.startBlock) {
1610
+ if (this.options.extensions && this.options.extensions.startBlock) {
1600
1611
  let startIndex = Infinity;
1601
1612
  const tempSrc = src.slice(1);
1602
1613
  let tempStart;
1603
1614
  this.options.extensions.startBlock.forEach(function(getStartIndex) {
1604
- tempStart = getStartIndex.call(this, tempSrc);
1615
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1605
1616
  if (typeof tempStart === 'number' && tempStart >= 0) { startIndex = Math.min(startIndex, tempStart); }
1606
1617
  });
1607
1618
  if (startIndex < Infinity && startIndex >= 0) {
1608
1619
  cutSrc = src.substring(0, startIndex + 1);
1609
1620
  }
1610
1621
  }
1611
- if (top && (token = this.tokenizer.paragraph(cutSrc))) {
1622
+ if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
1612
1623
  lastToken = tokens[tokens.length - 1];
1613
1624
  if (lastParagraphClipped && lastToken.type === 'paragraph') {
1614
1625
  lastToken.raw += '\n' + token.raw;
1615
1626
  lastToken.text += '\n' + token.text;
1627
+ this.inlineQueue.pop();
1628
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1616
1629
  } else {
1617
1630
  tokens.push(token);
1618
1631
  }
@@ -1628,6 +1641,8 @@ var Lexer_1 = class Lexer {
1628
1641
  if (lastToken && lastToken.type === 'text') {
1629
1642
  lastToken.raw += '\n' + token.raw;
1630
1643
  lastToken.text += '\n' + token.text;
1644
+ this.inlineQueue.pop();
1645
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1631
1646
  } else {
1632
1647
  tokens.push(token);
1633
1648
  }
@@ -1645,75 +1660,18 @@ var Lexer_1 = class Lexer {
1645
1660
  }
1646
1661
  }
1647
1662
 
1663
+ this.state.top = true;
1648
1664
  return tokens;
1649
1665
  }
1650
1666
 
1651
- inline(tokens) {
1652
- let i,
1653
- j,
1654
- k,
1655
- l2,
1656
- row,
1657
- token;
1658
-
1659
- const l = tokens.length;
1660
- for (i = 0; i < l; i++) {
1661
- token = tokens[i];
1662
- switch (token.type) {
1663
- case 'paragraph':
1664
- case 'text':
1665
- case 'heading': {
1666
- token.tokens = [];
1667
- this.inlineTokens(token.text, token.tokens);
1668
- break;
1669
- }
1670
- case 'table': {
1671
- token.tokens = {
1672
- header: [],
1673
- cells: []
1674
- };
1675
-
1676
- // header
1677
- l2 = token.header.length;
1678
- for (j = 0; j < l2; j++) {
1679
- token.tokens.header[j] = [];
1680
- this.inlineTokens(token.header[j], token.tokens.header[j]);
1681
- }
1682
-
1683
- // cells
1684
- l2 = token.cells.length;
1685
- for (j = 0; j < l2; j++) {
1686
- row = token.cells[j];
1687
- token.tokens.cells[j] = [];
1688
- for (k = 0; k < row.length; k++) {
1689
- token.tokens.cells[j][k] = [];
1690
- this.inlineTokens(row[k], token.tokens.cells[j][k]);
1691
- }
1692
- }
1693
-
1694
- break;
1695
- }
1696
- case 'blockquote': {
1697
- this.inline(token.tokens);
1698
- break;
1699
- }
1700
- case 'list': {
1701
- l2 = token.items.length;
1702
- for (j = 0; j < l2; j++) {
1703
- this.inline(token.items[j].tokens);
1704
- }
1705
- break;
1706
- }
1707
- }
1708
- }
1709
-
1710
- return tokens;
1667
+ inline(src, tokens) {
1668
+ this.inlineQueue.push({ src, tokens });
1711
1669
  }
1712
1670
 
1713
1671
  /**
1714
1672
  * Lexing/Compiling
1715
1673
  */
1716
- inlineTokens(src, tokens = [], inLink = false, inRawBlock = false) {
1674
+ inlineTokens(src, tokens = []) {
1717
1675
  let token, lastToken, cutSrc;
1718
1676
 
1719
1677
  // String with links masked to avoid interference with em and strong
@@ -1749,9 +1707,10 @@ var Lexer_1 = class Lexer {
1749
1707
  keepPrevChar = false;
1750
1708
 
1751
1709
  // extensions
1752
- if (this.options?.extensions?.inline
1710
+ if (this.options.extensions
1711
+ && this.options.extensions.inline
1753
1712
  && this.options.extensions.inline.some((extTokenizer) => {
1754
- if (token = extTokenizer.call(this, src, tokens)) {
1713
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1755
1714
  src = src.substring(token.raw.length);
1756
1715
  tokens.push(token);
1757
1716
  return true;
@@ -1769,10 +1728,8 @@ var Lexer_1 = class Lexer {
1769
1728
  }
1770
1729
 
1771
1730
  // tag
1772
- if (token = this.tokenizer.tag(src, inLink, inRawBlock)) {
1731
+ if (token = this.tokenizer.tag(src)) {
1773
1732
  src = src.substring(token.raw.length);
1774
- inLink = token.inLink;
1775
- inRawBlock = token.inRawBlock;
1776
1733
  lastToken = tokens[tokens.length - 1];
1777
1734
  if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1778
1735
  lastToken.raw += token.raw;
@@ -1786,9 +1743,6 @@ var Lexer_1 = class Lexer {
1786
1743
  // link
1787
1744
  if (token = this.tokenizer.link(src)) {
1788
1745
  src = src.substring(token.raw.length);
1789
- if (token.type === 'link') {
1790
- token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
1791
- }
1792
1746
  tokens.push(token);
1793
1747
  continue;
1794
1748
  }
@@ -1797,10 +1751,7 @@ var Lexer_1 = class Lexer {
1797
1751
  if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1798
1752
  src = src.substring(token.raw.length);
1799
1753
  lastToken = tokens[tokens.length - 1];
1800
- if (token.type === 'link') {
1801
- token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
1802
- tokens.push(token);
1803
- } else if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1754
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1804
1755
  lastToken.raw += token.raw;
1805
1756
  lastToken.text += token.text;
1806
1757
  } else {
@@ -1812,7 +1763,6 @@ var Lexer_1 = class Lexer {
1812
1763
  // em & strong
1813
1764
  if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
1814
1765
  src = src.substring(token.raw.length);
1815
- token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1816
1766
  tokens.push(token);
1817
1767
  continue;
1818
1768
  }
@@ -1834,7 +1784,6 @@ var Lexer_1 = class Lexer {
1834
1784
  // del (gfm)
1835
1785
  if (token = this.tokenizer.del(src)) {
1836
1786
  src = src.substring(token.raw.length);
1837
- token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1838
1787
  tokens.push(token);
1839
1788
  continue;
1840
1789
  }
@@ -1847,7 +1796,7 @@ var Lexer_1 = class Lexer {
1847
1796
  }
1848
1797
 
1849
1798
  // url (gfm)
1850
- if (!inLink && (token = this.tokenizer.url(src, mangle))) {
1799
+ if (!this.state.inLink && (token = this.tokenizer.url(src, mangle))) {
1851
1800
  src = src.substring(token.raw.length);
1852
1801
  tokens.push(token);
1853
1802
  continue;
@@ -1856,19 +1805,19 @@ var Lexer_1 = class Lexer {
1856
1805
  // text
1857
1806
  // prevent inlineText consuming extensions by clipping 'src' to extension start
1858
1807
  cutSrc = src;
1859
- if (this.options.extensions?.startInline) {
1808
+ if (this.options.extensions && this.options.extensions.startInline) {
1860
1809
  let startIndex = Infinity;
1861
1810
  const tempSrc = src.slice(1);
1862
1811
  let tempStart;
1863
1812
  this.options.extensions.startInline.forEach(function(getStartIndex) {
1864
- tempStart = getStartIndex.call(this, tempSrc);
1813
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1865
1814
  if (typeof tempStart === 'number' && tempStart >= 0) { startIndex = Math.min(startIndex, tempStart); }
1866
1815
  });
1867
1816
  if (startIndex < Infinity && startIndex >= 0) {
1868
1817
  cutSrc = src.substring(0, startIndex + 1);
1869
1818
  }
1870
1819
  }
1871
- if (token = this.tokenizer.inlineText(cutSrc, inRawBlock, smartypants)) {
1820
+ if (token = this.tokenizer.inlineText(cutSrc, smartypants)) {
1872
1821
  src = src.substring(token.raw.length);
1873
1822
  if (token.raw.slice(-1) !== '_') { // Track prevChar before string of ____ started
1874
1823
  prevChar = token.raw.slice(-1);
@@ -2228,8 +2177,8 @@ var Parser_1 = class Parser {
2228
2177
  token = tokens[i];
2229
2178
 
2230
2179
  // Run any renderer extensions
2231
- if (this.options.extensions?.renderers?.[token.type]) {
2232
- ret = this.options.extensions.renderers[token.type].call(this, token);
2180
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
2181
+ ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
2233
2182
  if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(token.type)) {
2234
2183
  out += ret || '';
2235
2184
  continue;
@@ -2266,22 +2215,22 @@ var Parser_1 = class Parser {
2266
2215
  l2 = token.header.length;
2267
2216
  for (j = 0; j < l2; j++) {
2268
2217
  cell += this.renderer.tablecell(
2269
- this.parseInline(token.tokens.header[j]),
2218
+ this.parseInline(token.header[j].tokens),
2270
2219
  { header: true, align: token.align[j] }
2271
2220
  );
2272
2221
  }
2273
2222
  header += this.renderer.tablerow(cell);
2274
2223
 
2275
2224
  body = '';
2276
- l2 = token.cells.length;
2225
+ l2 = token.rows.length;
2277
2226
  for (j = 0; j < l2; j++) {
2278
- row = token.tokens.cells[j];
2227
+ row = token.rows[j];
2279
2228
 
2280
2229
  cell = '';
2281
2230
  l3 = row.length;
2282
2231
  for (k = 0; k < l3; k++) {
2283
2232
  cell += this.renderer.tablecell(
2284
- this.parseInline(row[k]),
2233
+ this.parseInline(row[k].tokens),
2285
2234
  { header: false, align: token.align[k] }
2286
2235
  );
2287
2236
  }
@@ -2312,7 +2261,7 @@ var Parser_1 = class Parser {
2312
2261
  if (item.task) {
2313
2262
  checkbox = this.renderer.checkbox(checked);
2314
2263
  if (loose) {
2315
- if (item.tokens.length > 0 && item.tokens[0].type === 'text') {
2264
+ if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
2316
2265
  item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
2317
2266
  if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
2318
2267
  item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
@@ -2384,8 +2333,8 @@ var Parser_1 = class Parser {
2384
2333
  token = tokens[i];
2385
2334
 
2386
2335
  // Run any renderer extensions
2387
- if (this.options.extensions?.renderers?.[token.type]) {
2388
- ret = this.options.extensions.renderers[token.type].call(this, token);
2336
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
2337
+ ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
2389
2338
  if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(token.type)) {
2390
2339
  out += ret || '';
2391
2340
  continue;
@@ -2605,7 +2554,7 @@ marked.use = function(...args) {
2605
2554
  throw new Error('extension name required');
2606
2555
  }
2607
2556
  if (ext.renderer) { // Renderer extensions
2608
- const prevRenderer = extensions.renderers?.[ext.name];
2557
+ const prevRenderer = extensions.renderers ? extensions.renderers[ext.name] : null;
2609
2558
  if (prevRenderer) {
2610
2559
  // Replace extension with func to run new extension but fall back if false
2611
2560
  extensions.renderers[ext.name] = function(...args) {
@@ -2710,12 +2659,12 @@ marked.walkTokens = function(tokens, callback) {
2710
2659
  callback(token);
2711
2660
  switch (token.type) {
2712
2661
  case 'table': {
2713
- for (const cell of token.tokens.header) {
2714
- marked.walkTokens(cell, callback);
2662
+ for (const cell of token.header) {
2663
+ marked.walkTokens(cell.tokens, callback);
2715
2664
  }
2716
- for (const row of token.tokens.cells) {
2665
+ for (const row of token.rows) {
2717
2666
  for (const cell of row) {
2718
- marked.walkTokens(cell, callback);
2667
+ marked.walkTokens(cell.tokens, callback);
2719
2668
  }
2720
2669
  }
2721
2670
  break;
@@ -2725,12 +2674,11 @@ marked.walkTokens = function(tokens, callback) {
2725
2674
  break;
2726
2675
  }
2727
2676
  default: {
2728
- if (marked.defaults?.extensions?.childTokens?.[token.type]) { // Walk any extensions
2729
- marked.defaults?.extensions.childTokens[token.type].forEach(function(childTokens) {
2677
+ if (marked.defaults.extensions && marked.defaults.extensions.childTokens && marked.defaults.extensions.childTokens[token.type]) { // Walk any extensions
2678
+ marked.defaults.extensions.childTokens[token.type].forEach(function(childTokens) {
2730
2679
  marked.walkTokens(token[childTokens], callback);
2731
2680
  });
2732
- }
2733
- if (token.tokens && !marked.defaults?.extensions?.childTokens[token.type]) {
2681
+ } else if (token.tokens) {
2734
2682
  marked.walkTokens(token.tokens, callback);
2735
2683
  }
2736
2684
  }
@@ -2792,4 +2740,4 @@ marked.parse = marked;
2792
2740
 
2793
2741
  var marked_1 = marked;
2794
2742
 
2795
- export default marked_1;
2743
+ export { marked_1 as default };