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.js CHANGED
@@ -284,7 +284,15 @@
284
284
  }
285
285
  }),
286
286
  cells = row.split(/ \|/);
287
- var i = 0;
287
+ var i = 0; // First/last cell in a row cannot be empty if it has no leading/trailing pipe
288
+
289
+ if (!cells[0].trim()) {
290
+ cells.shift();
291
+ }
292
+
293
+ if (!cells[cells.length - 1].trim()) {
294
+ cells.pop();
295
+ }
288
296
 
289
297
  if (cells.length > count) {
290
298
  cells.splice(count);
@@ -403,18 +411,20 @@
403
411
  _escape = helpers.escape,
404
412
  findClosingBracket = helpers.findClosingBracket;
405
413
 
406
- function outputLink(cap, link, raw) {
414
+ function outputLink(cap, link, raw, lexer) {
407
415
  var href = link.href;
408
416
  var title = link.title ? _escape(link.title) : null;
409
417
  var text = cap[1].replace(/\\([\[\]])/g, '$1');
410
418
 
411
419
  if (cap[0].charAt(0) !== '!') {
420
+ lexer.state.inLink = true;
412
421
  return {
413
422
  type: 'link',
414
423
  raw: raw,
415
424
  href: href,
416
425
  title: title,
417
- text: text
426
+ text: text,
427
+ tokens: lexer.inlineTokens(text, [])
418
428
  };
419
429
  } else {
420
430
  return {
@@ -526,51 +536,15 @@
526
536
  }
527
537
  }
528
538
 
529
- return {
539
+ var token = {
530
540
  type: 'heading',
531
541
  raw: cap[0],
532
542
  depth: cap[1].length,
533
- text: text
534
- };
535
- }
536
- };
537
-
538
- _proto.nptable = function nptable(src) {
539
- var cap = this.rules.block.nptable.exec(src);
540
-
541
- if (cap) {
542
- var item = {
543
- type: 'table',
544
- header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
545
- align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
546
- cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [],
547
- raw: cap[0]
543
+ text: text,
544
+ tokens: []
548
545
  };
549
-
550
- if (item.header.length === item.align.length) {
551
- var l = item.align.length;
552
- var i;
553
-
554
- for (i = 0; i < l; i++) {
555
- if (/^ *-+: *$/.test(item.align[i])) {
556
- item.align[i] = 'right';
557
- } else if (/^ *:-+: *$/.test(item.align[i])) {
558
- item.align[i] = 'center';
559
- } else if (/^ *:-+ *$/.test(item.align[i])) {
560
- item.align[i] = 'left';
561
- } else {
562
- item.align[i] = null;
563
- }
564
- }
565
-
566
- l = item.cells.length;
567
-
568
- for (i = 0; i < l; i++) {
569
- item.cells[i] = splitCells(item.cells[i], item.header.length);
570
- }
571
-
572
- return item;
573
- }
546
+ this.lexer.inline(token.text, token.tokens);
547
+ return token;
574
548
  }
575
549
  };
576
550
 
@@ -593,6 +567,7 @@
593
567
  return {
594
568
  type: 'blockquote',
595
569
  raw: cap[0],
570
+ tokens: this.lexer.blockTokens(text, []),
596
571
  text: text
597
572
  };
598
573
  }
@@ -602,121 +577,150 @@
602
577
  var cap = this.rules.block.list.exec(src);
603
578
 
604
579
  if (cap) {
605
- var raw = cap[0];
606
- var bull = cap[2];
580
+ var raw, istask, ischecked, indent, i, blankLine, endsWithBlankLine, line, lines, itemContents;
581
+ var bull = cap[1].trim();
607
582
  var isordered = bull.length > 1;
608
583
  var list = {
609
584
  type: 'list',
610
- raw: raw,
585
+ raw: '',
611
586
  ordered: isordered,
612
587
  start: isordered ? +bull.slice(0, -1) : '',
613
588
  loose: false,
614
589
  items: []
615
- }; // Get each top-level item.
616
-
617
- var itemMatch = cap[0].match(this.rules.block.item);
618
- var next = false,
619
- item,
620
- space,
621
- bcurr,
622
- bnext,
623
- addBack,
624
- loose,
625
- istask,
626
- ischecked,
627
- endMatch;
628
- var l = itemMatch.length;
629
- bcurr = this.rules.block.listItemStart.exec(itemMatch[0]);
630
-
631
- for (var i = 0; i < l; i++) {
632
- item = itemMatch[i];
633
- raw = item;
634
-
635
- if (!this.options.pedantic) {
636
- // Determine if current item contains the end of the list
637
- endMatch = item.match(new RegExp('\\n\\s*\\n {0,' + (bcurr[0].length - 1) + '}\\S'));
638
-
639
- if (endMatch) {
640
- addBack = item.length - endMatch.index + itemMatch.slice(i + 1).join('\n').length;
641
- list.raw = list.raw.substring(0, list.raw.length - addBack);
642
- item = item.substring(0, endMatch.index);
643
- raw = item;
644
- l = i + 1;
645
- }
646
- } // Determine whether the next list item belongs here.
647
- // Backpedal if it does not belong in this list.
590
+ };
591
+ bull = isordered ? "\\d{1,9}\\" + bull.slice(-1) : "\\" + bull;
648
592
 
593
+ if (this.options.pedantic) {
594
+ bull = isordered ? bull : '[*+-]';
595
+ } // Get next list item
649
596
 
650
- if (i !== l - 1) {
651
- bnext = this.rules.block.listItemStart.exec(itemMatch[i + 1]);
652
597
 
653
- if (!this.options.pedantic ? bnext[1].length >= bcurr[0].length || bnext[1].length > 3 : bnext[1].length > bcurr[1].length) {
654
- // nested list or continuation
655
- itemMatch.splice(i, 2, itemMatch[i] + (!this.options.pedantic && bnext[1].length < bcurr[0].length && !itemMatch[i].match(/\n$/) ? '' : '\n') + itemMatch[i + 1]);
656
- i--;
657
- l--;
658
- continue;
659
- } else if ( // different bullet style
660
- !this.options.pedantic || this.options.smartLists ? bnext[2][bnext[2].length - 1] !== bull[bull.length - 1] : isordered === (bnext[2].length === 1)) {
661
- addBack = itemMatch.slice(i + 1).join('\n').length;
662
- list.raw = list.raw.substring(0, list.raw.length - addBack);
663
- i = l - 1;
664
- }
598
+ var itemRegex = new RegExp("^( {0,3}" + bull + ")((?: [^\\n]*| *)(?:\\n[^\\n]*)*(?:\\n|$))"); // Get each top-level item
665
599
 
666
- bcurr = bnext;
667
- } // Remove the list item's bullet
668
- // so it is seen as the next token.
600
+ while (src) {
601
+ if (this.rules.block.hr.test(src)) {
602
+ // End list if we encounter an HR (possibly move into itemRegex?)
603
+ break;
604
+ }
669
605
 
606
+ if (!(cap = itemRegex.exec(src))) {
607
+ break;
608
+ }
609
+
610
+ lines = cap[2].split('\n');
611
+
612
+ if (this.options.pedantic) {
613
+ indent = 2;
614
+ itemContents = lines[0].trimLeft();
615
+ } else {
616
+ indent = cap[2].search(/[^ ]/); // Find first non-space char
617
+
618
+ indent = cap[1].length + (indent > 4 ? 1 : indent); // intented code blocks after 4 spaces; indent is always 1
619
+
620
+ itemContents = lines[0].slice(indent - cap[1].length);
621
+ }
622
+
623
+ blankLine = false;
624
+ raw = cap[0];
625
+
626
+ if (!lines[0] && /^ *$/.test(lines[1])) {
627
+ // items begin with at most one blank line
628
+ raw = cap[1] + lines.slice(0, 2).join('\n') + '\n';
629
+ list.loose = true;
630
+ lines = [];
631
+ }
632
+
633
+ var nextBulletRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:[*+-]|\\d{1,9}[.)])");
634
+
635
+ for (i = 1; i < lines.length; i++) {
636
+ line = lines[i];
670
637
 
671
- space = item.length;
672
- item = item.replace(/^ *([*+-]|\d+[.)]) ?/, ''); // Outdent whatever the
673
- // list item contains. Hacky.
638
+ if (this.options.pedantic) {
639
+ // Re-align to follow commonmark nesting rules
640
+ line = line.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
641
+ } // End list item if found start of new bullet
642
+
643
+
644
+ if (nextBulletRegex.test(line)) {
645
+ raw = cap[1] + lines.slice(0, i).join('\n') + '\n';
646
+ break;
647
+ } // Until we encounter a blank line, item contents do not need indentation
674
648
 
675
- if (~item.indexOf('\n ')) {
676
- space -= item.length;
677
- item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, '');
678
- } // trim item newlines at end
679
649
 
650
+ if (!blankLine) {
651
+ if (!line.trim()) {
652
+ // Check if current line is empty
653
+ blankLine = true;
654
+ } // Dedent if possible
680
655
 
681
- item = rtrim(item, '\n');
682
656
 
683
- if (i !== l - 1) {
684
- raw = raw + '\n';
685
- } // Determine whether item is loose or not.
686
- // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
687
- // for discount behavior.
657
+ if (line.search(/[^ ]/) >= indent) {
658
+ itemContents += '\n' + line.slice(indent);
659
+ } else {
660
+ itemContents += '\n' + line;
661
+ }
688
662
 
663
+ continue;
664
+ } // Dedent this line
689
665
 
690
- loose = next || /\n\n(?!\s*$)/.test(raw);
691
666
 
692
- if (i !== l - 1) {
693
- next = raw.slice(-2) === '\n\n';
694
- if (!loose) loose = next;
667
+ if (line.search(/[^ ]/) >= indent || !line.trim()) {
668
+ itemContents += '\n' + line.slice(indent);
669
+ continue;
670
+ } else {
671
+ // Line was not properly indented; end of this item
672
+ raw = cap[1] + lines.slice(0, i).join('\n') + '\n';
673
+ break;
674
+ }
695
675
  }
696
676
 
697
- if (loose) {
698
- list.loose = true;
677
+ if (!list.loose) {
678
+ // If the previous item ended with a blank line, the list is loose
679
+ if (endsWithBlankLine) {
680
+ list.loose = true;
681
+ } else if (/\n *\n *$/.test(raw)) {
682
+ endsWithBlankLine = true;
683
+ }
699
684
  } // Check for task list items
700
685
 
701
686
 
702
687
  if (this.options.gfm) {
703
- istask = /^\[[ xX]\] /.test(item);
704
- ischecked = undefined;
688
+ istask = /^\[[ xX]\] /.exec(itemContents);
705
689
 
706
690
  if (istask) {
707
- ischecked = item[1] !== ' ';
708
- item = item.replace(/^\[[ xX]\] +/, '');
691
+ ischecked = istask[0] !== '[ ] ';
692
+ itemContents = itemContents.replace(/^\[[ xX]\] +/, '');
709
693
  }
710
694
  }
711
695
 
712
696
  list.items.push({
713
697
  type: 'list_item',
714
698
  raw: raw,
715
- task: istask,
699
+ task: !!istask,
716
700
  checked: ischecked,
717
- loose: loose,
718
- text: item
701
+ loose: false,
702
+ text: itemContents
719
703
  });
704
+ list.raw += raw;
705
+ src = src.slice(raw.length);
706
+ } // Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
707
+
708
+
709
+ list.items[list.items.length - 1].raw = raw.trimRight();
710
+ list.items[list.items.length - 1].text = itemContents.trimRight();
711
+ list.raw = list.raw.trimRight();
712
+ var l = list.items.length; // Item child tokens handled here at end because we needed to have the final item to trim it first
713
+
714
+ for (i = 0; i < l; i++) {
715
+ this.lexer.state.top = false;
716
+ list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
717
+
718
+ if (list.items[i].tokens.some(function (t) {
719
+ return t.type === 'space';
720
+ })) {
721
+ list.loose = true;
722
+ list.items[i].loose = true;
723
+ }
720
724
  }
721
725
 
722
726
  return list;
@@ -727,12 +731,21 @@
727
731
  var cap = this.rules.block.html.exec(src);
728
732
 
729
733
  if (cap) {
730
- return {
731
- type: this.options.sanitize ? 'paragraph' : 'html',
734
+ var token = {
735
+ type: 'html',
732
736
  raw: cap[0],
733
737
  pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
734
- text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
738
+ text: cap[0]
735
739
  };
740
+
741
+ if (this.options.sanitize) {
742
+ token.type = 'paragraph';
743
+ token.text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]);
744
+ token.tokens = [];
745
+ this.lexer.inline(token.text, token.tokens);
746
+ }
747
+
748
+ return token;
736
749
  }
737
750
  };
738
751
 
@@ -758,15 +771,19 @@
758
771
  if (cap) {
759
772
  var item = {
760
773
  type: 'table',
761
- header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
774
+ header: splitCells(cap[1]).map(function (c) {
775
+ return {
776
+ text: c
777
+ };
778
+ }),
762
779
  align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
763
- cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
780
+ rows: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
764
781
  };
765
782
 
766
783
  if (item.header.length === item.align.length) {
767
784
  item.raw = cap[0];
768
785
  var l = item.align.length;
769
- var i;
786
+ var i, j, k, row;
770
787
 
771
788
  for (i = 0; i < l; i++) {
772
789
  if (/^ *-+: *$/.test(item.align[i])) {
@@ -780,10 +797,35 @@
780
797
  }
781
798
  }
782
799
 
783
- l = item.cells.length;
800
+ l = item.rows.length;
784
801
 
785
802
  for (i = 0; i < l; i++) {
786
- item.cells[i] = splitCells(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length);
803
+ item.rows[i] = splitCells(item.rows[i], item.header.length).map(function (c) {
804
+ return {
805
+ text: c
806
+ };
807
+ });
808
+ } // parse child tokens inside headers and cells
809
+ // header child tokens
810
+
811
+
812
+ l = item.header.length;
813
+
814
+ for (j = 0; j < l; j++) {
815
+ item.header[j].tokens = [];
816
+ this.lexer.inlineTokens(item.header[j].text, item.header[j].tokens);
817
+ } // cell child tokens
818
+
819
+
820
+ l = item.rows.length;
821
+
822
+ for (j = 0; j < l; j++) {
823
+ row = item.rows[j];
824
+
825
+ for (k = 0; k < row.length; k++) {
826
+ row[k].tokens = [];
827
+ this.lexer.inlineTokens(row[k].text, row[k].tokens);
828
+ }
787
829
  }
788
830
 
789
831
  return item;
@@ -795,12 +837,15 @@
795
837
  var cap = this.rules.block.lheading.exec(src);
796
838
 
797
839
  if (cap) {
798
- return {
840
+ var token = {
799
841
  type: 'heading',
800
842
  raw: cap[0],
801
843
  depth: cap[2].charAt(0) === '=' ? 1 : 2,
802
- text: cap[1]
844
+ text: cap[1],
845
+ tokens: []
803
846
  };
847
+ this.lexer.inline(token.text, token.tokens);
848
+ return token;
804
849
  }
805
850
  };
806
851
 
@@ -808,11 +853,14 @@
808
853
  var cap = this.rules.block.paragraph.exec(src);
809
854
 
810
855
  if (cap) {
811
- return {
856
+ var token = {
812
857
  type: 'paragraph',
813
858
  raw: cap[0],
814
- text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1]
859
+ text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1],
860
+ tokens: []
815
861
  };
862
+ this.lexer.inline(token.text, token.tokens);
863
+ return token;
816
864
  }
817
865
  };
818
866
 
@@ -820,11 +868,14 @@
820
868
  var cap = this.rules.block.text.exec(src);
821
869
 
822
870
  if (cap) {
823
- return {
871
+ var token = {
824
872
  type: 'text',
825
873
  raw: cap[0],
826
- text: cap[0]
874
+ text: cap[0],
875
+ tokens: []
827
876
  };
877
+ this.lexer.inline(token.text, token.tokens);
878
+ return token;
828
879
  }
829
880
  };
830
881
 
@@ -840,27 +891,27 @@
840
891
  }
841
892
  };
842
893
 
843
- _proto.tag = function tag(src, inLink, inRawBlock) {
894
+ _proto.tag = function tag(src) {
844
895
  var cap = this.rules.inline.tag.exec(src);
845
896
 
846
897
  if (cap) {
847
- if (!inLink && /^<a /i.test(cap[0])) {
848
- inLink = true;
849
- } else if (inLink && /^<\/a>/i.test(cap[0])) {
850
- inLink = false;
898
+ if (!this.lexer.state.inLink && /^<a /i.test(cap[0])) {
899
+ this.lexer.state.inLink = true;
900
+ } else if (this.lexer.state.inLink && /^<\/a>/i.test(cap[0])) {
901
+ this.lexer.state.inLink = false;
851
902
  }
852
903
 
853
- if (!inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
854
- inRawBlock = true;
855
- } else if (inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
856
- inRawBlock = false;
904
+ if (!this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
905
+ this.lexer.state.inRawBlock = true;
906
+ } else if (this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
907
+ this.lexer.state.inRawBlock = false;
857
908
  }
858
909
 
859
910
  return {
860
911
  type: this.options.sanitize ? 'text' : 'html',
861
912
  raw: cap[0],
862
- inLink: inLink,
863
- inRawBlock: inRawBlock,
913
+ inLink: this.lexer.state.inLink,
914
+ inRawBlock: this.lexer.state.inRawBlock,
864
915
  text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
865
916
  };
866
917
  }
@@ -926,7 +977,7 @@
926
977
  return outputLink(cap, {
927
978
  href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
928
979
  title: title ? title.replace(this.rules.inline._escapes, '$1') : title
929
- }, cap[0]);
980
+ }, cap[0], this.lexer);
930
981
  }
931
982
  };
932
983
 
@@ -946,7 +997,7 @@
946
997
  };
947
998
  }
948
999
 
949
- return outputLink(cap, link, cap[0]);
1000
+ return outputLink(cap, link, cap[0], this.lexer);
950
1001
  }
951
1002
  };
952
1003
 
@@ -997,18 +1048,23 @@
997
1048
  rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal); // Create `em` if smallest delimiter has odd char count. *a***
998
1049
 
999
1050
  if (Math.min(lLength, rLength) % 2) {
1051
+ var _text = src.slice(1, lLength + match.index + rLength);
1052
+
1000
1053
  return {
1001
1054
  type: 'em',
1002
1055
  raw: src.slice(0, lLength + match.index + rLength + 1),
1003
- text: src.slice(1, lLength + match.index + rLength)
1056
+ text: _text,
1057
+ tokens: this.lexer.inlineTokens(_text, [])
1004
1058
  };
1005
1059
  } // Create 'strong' if smallest delimiter has even char count. **a***
1006
1060
 
1007
1061
 
1062
+ var text = src.slice(2, lLength + match.index + rLength - 1);
1008
1063
  return {
1009
1064
  type: 'strong',
1010
1065
  raw: src.slice(0, lLength + match.index + rLength + 1),
1011
- text: src.slice(2, lLength + match.index + rLength - 1)
1066
+ text: text,
1067
+ tokens: this.lexer.inlineTokens(text, [])
1012
1068
  };
1013
1069
  }
1014
1070
  }
@@ -1053,7 +1109,8 @@
1053
1109
  return {
1054
1110
  type: 'del',
1055
1111
  raw: cap[0],
1056
- text: cap[2]
1112
+ text: cap[2],
1113
+ tokens: this.lexer.inlineTokens(cap[2], [])
1057
1114
  };
1058
1115
  }
1059
1116
  };
@@ -1127,13 +1184,13 @@
1127
1184
  }
1128
1185
  };
1129
1186
 
1130
- _proto.inlineText = function inlineText(src, inRawBlock, smartypants) {
1187
+ _proto.inlineText = function inlineText(src, smartypants) {
1131
1188
  var cap = this.rules.inline.text.exec(src);
1132
1189
 
1133
1190
  if (cap) {
1134
1191
  var text;
1135
1192
 
1136
- if (inRawBlock) {
1193
+ if (this.lexer.state.inRawBlock) {
1137
1194
  text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0];
1138
1195
  } else {
1139
1196
  text = _escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
@@ -1160,23 +1217,22 @@
1160
1217
  var block$1 = {
1161
1218
  newline: /^(?: *(?:\n|$))+/,
1162
1219
  code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
1163
- fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
1220
+ fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
1164
1221
  hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
1165
1222
  heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
1166
1223
  blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
1167
- list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?! {0,3}bull )\n*|\s*$)/,
1224
+ list: /^( {0,3}bull)( [^\n]+?)?(?:\n|$)/,
1168
1225
  html: '^ {0,3}(?:' // optional indentation
1169
- + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
1226
+ + '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
1170
1227
  + '|comment[^\\n]*(\\n+|$)' // (2)
1171
1228
  + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
1172
1229
  + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
1173
1230
  + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
1174
1231
  + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (6)
1175
- + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
1176
- + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
1232
+ + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
1233
+ + '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
1177
1234
  + ')',
1178
1235
  def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
1179
- nptable: noopTest,
1180
1236
  table: noopTest,
1181
1237
  lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
1182
1238
  // regex template, placeholders will be replaced according to different paragraph
@@ -1188,8 +1244,6 @@
1188
1244
  block$1._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
1189
1245
  block$1.def = edit(block$1.def).replace('label', block$1._label).replace('title', block$1._title).getRegex();
1190
1246
  block$1.bullet = /(?:[*+-]|\d{1,9}[.)])/;
1191
- block$1.item = /^( *)(bull) ?[^\n]*(?:\n(?! *bull ?)[^\n]*)*/;
1192
- block$1.item = edit(block$1.item, 'gm').replace(/bull/g, block$1.bullet).getRegex();
1193
1247
  block$1.listItemStart = edit(/^( *)(bull) */).replace('bull', block$1.bullet).getRegex();
1194
1248
  block$1.list = edit(block$1.list).replace(/bull/g, block$1.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block$1.def.source + ')').getRegex();
1195
1249
  block$1._tag = 'address|article|aside|base|basefont|blockquote|body|caption' + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption' + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe' + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option' + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr' + '|track|ul';
@@ -1197,7 +1251,7 @@
1197
1251
  block$1.html = edit(block$1.html, 'i').replace('comment', block$1._comment).replace('tag', block$1._tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
1198
1252
  block$1.paragraph = edit(block$1._paragraph).replace('hr', block$1.hr).replace('heading', ' {0,3}#{1,6} ').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
1199
1253
  .replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1200
- .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block$1._tag) // pars can be interrupted by type (6) html blocks
1254
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', block$1._tag) // pars can be interrupted by type (6) html blocks
1201
1255
  .getRegex();
1202
1256
  block$1.blockquote = edit(block$1.blockquote).replace('paragraph', block$1.paragraph).getRegex();
1203
1257
  /**
@@ -1210,20 +1264,13 @@
1210
1264
  */
1211
1265
 
1212
1266
  block$1.gfm = merge$1({}, block$1.normal, {
1213
- nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
1214
- + ' {0,3}([-:]+ *\\|[-| :]*)' // Align
1215
- + '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)',
1216
- // Cells
1217
- table: '^ *\\|(.+)\\n' // Header
1218
- + ' {0,3}\\|?( *[-:]+[-| :]*)' // Align
1267
+ table: '^ *([^\\n ].*\\|.*)\\n' // Header
1268
+ + ' {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)\\|?' // Align
1219
1269
  + '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
1220
1270
 
1221
1271
  });
1222
- block$1.gfm.nptable = edit(block$1.gfm.nptable).replace('hr', block$1.hr).replace('heading', ' {0,3}#{1,6} ').replace('blockquote', ' {0,3}>').replace('code', ' {4}[^\\n]').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1223
- .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block$1._tag) // tables can be interrupted by type (6) html blocks
1224
- .getRegex();
1225
1272
  block$1.gfm.table = edit(block$1.gfm.table).replace('hr', block$1.hr).replace('heading', ' {0,3}#{1,6} ').replace('blockquote', ' {0,3}>').replace('code', ' {4}[^\\n]').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1226
- .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block$1._tag) // tables can be interrupted by type (6) html blocks
1273
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', block$1._tag) // tables can be interrupted by type (6) html blocks
1227
1274
  .getRegex();
1228
1275
  /**
1229
1276
  * Pedantic grammar (original John Gruber's loose markdown specification)
@@ -1399,6 +1446,13 @@
1399
1446
  this.options.tokenizer = this.options.tokenizer || new Tokenizer$1();
1400
1447
  this.tokenizer = this.options.tokenizer;
1401
1448
  this.tokenizer.options = this.options;
1449
+ this.tokenizer.lexer = this;
1450
+ this.inlineQueue = [];
1451
+ this.state = {
1452
+ inLink: false,
1453
+ inRawBlock: false,
1454
+ top: true
1455
+ };
1402
1456
  var rules = {
1403
1457
  block: block.normal,
1404
1458
  inline: inline.normal
@@ -1449,8 +1503,13 @@
1449
1503
 
1450
1504
  _proto.lex = function lex(src) {
1451
1505
  src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ');
1452
- this.blockTokens(src, this.tokens, true);
1453
- this.inline(this.tokens);
1506
+ this.blockTokens(src, this.tokens);
1507
+ var next;
1508
+
1509
+ while (next = this.inlineQueue.shift()) {
1510
+ this.inlineTokens(next.src, next.tokens);
1511
+ }
1512
+
1454
1513
  return this.tokens;
1455
1514
  }
1456
1515
  /**
@@ -1458,28 +1517,24 @@
1458
1517
  */
1459
1518
  ;
1460
1519
 
1461
- _proto.blockTokens = function blockTokens(src, tokens, top) {
1520
+ _proto.blockTokens = function blockTokens(src, tokens) {
1462
1521
  var _this = this;
1463
1522
 
1464
1523
  if (tokens === void 0) {
1465
1524
  tokens = [];
1466
1525
  }
1467
1526
 
1468
- if (top === void 0) {
1469
- top = true;
1470
- }
1471
-
1472
1527
  if (this.options.pedantic) {
1473
1528
  src = src.replace(/^ +$/gm, '');
1474
1529
  }
1475
1530
 
1476
- var token, i, l, lastToken, cutSrc, lastParagraphClipped;
1531
+ var token, lastToken, cutSrc, lastParagraphClipped;
1477
1532
 
1478
1533
  while (src) {
1479
- var _this$options, _this$options$extensi, _this$options$extensi2;
1480
-
1481
- if ((_this$options = this.options) != null && (_this$options$extensi = _this$options.extensions) != null && _this$options$extensi.block && this.options.extensions.block.some(function (extTokenizer) {
1482
- if (token = extTokenizer.call(_this, src, tokens)) {
1534
+ if (this.options.extensions && this.options.extensions.block && this.options.extensions.block.some(function (extTokenizer) {
1535
+ if (token = extTokenizer.call({
1536
+ lexer: _this
1537
+ }, src, tokens)) {
1483
1538
  src = src.substring(token.raw.length);
1484
1539
  tokens.push(token);
1485
1540
  return true;
@@ -1506,9 +1561,10 @@
1506
1561
  src = src.substring(token.raw.length);
1507
1562
  lastToken = tokens[tokens.length - 1]; // An indented code block cannot interrupt a paragraph.
1508
1563
 
1509
- if (lastToken && lastToken.type === 'paragraph') {
1564
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1510
1565
  lastToken.raw += '\n' + token.raw;
1511
1566
  lastToken.text += '\n' + token.text;
1567
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1512
1568
  } else {
1513
1569
  tokens.push(token);
1514
1570
  }
@@ -1528,13 +1584,6 @@
1528
1584
  src = src.substring(token.raw.length);
1529
1585
  tokens.push(token);
1530
1586
  continue;
1531
- } // table no leading pipe (gfm)
1532
-
1533
-
1534
- if (token = this.tokenizer.nptable(src)) {
1535
- src = src.substring(token.raw.length);
1536
- tokens.push(token);
1537
- continue;
1538
1587
  } // hr
1539
1588
 
1540
1589
 
@@ -1547,7 +1596,6 @@
1547
1596
 
1548
1597
  if (token = this.tokenizer.blockquote(src)) {
1549
1598
  src = src.substring(token.raw.length);
1550
- token.tokens = this.blockTokens(token.text, [], top);
1551
1599
  tokens.push(token);
1552
1600
  continue;
1553
1601
  } // list
@@ -1555,12 +1603,6 @@
1555
1603
 
1556
1604
  if (token = this.tokenizer.list(src)) {
1557
1605
  src = src.substring(token.raw.length);
1558
- l = token.items.length;
1559
-
1560
- for (i = 0; i < l; i++) {
1561
- token.items[i].tokens = this.blockTokens(token.items[i].text, [], false);
1562
- }
1563
-
1564
1606
  tokens.push(token);
1565
1607
  continue;
1566
1608
  } // html
@@ -1573,10 +1615,15 @@
1573
1615
  } // def
1574
1616
 
1575
1617
 
1576
- if (top && (token = this.tokenizer.def(src))) {
1618
+ if (token = this.tokenizer.def(src)) {
1577
1619
  src = src.substring(token.raw.length);
1620
+ lastToken = tokens[tokens.length - 1];
1578
1621
 
1579
- if (!this.tokens.links[token.tag]) {
1622
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1623
+ lastToken.raw += '\n' + token.raw;
1624
+ lastToken.text += '\n' + token.raw;
1625
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1626
+ } else if (!this.tokens.links[token.tag]) {
1580
1627
  this.tokens.links[token.tag] = {
1581
1628
  href: token.href,
1582
1629
  title: token.title
@@ -1604,14 +1651,16 @@
1604
1651
 
1605
1652
  cutSrc = src;
1606
1653
 
1607
- if ((_this$options$extensi2 = this.options.extensions) != null && _this$options$extensi2.startBlock) {
1654
+ if (this.options.extensions && this.options.extensions.startBlock) {
1608
1655
  (function () {
1609
1656
  var startIndex = Infinity;
1610
1657
  var tempSrc = src.slice(1);
1611
1658
  var tempStart = void 0;
1612
1659
 
1613
1660
  _this.options.extensions.startBlock.forEach(function (getStartIndex) {
1614
- tempStart = getStartIndex.call(this, tempSrc);
1661
+ tempStart = getStartIndex.call({
1662
+ lexer: this
1663
+ }, tempSrc);
1615
1664
 
1616
1665
  if (typeof tempStart === 'number' && tempStart >= 0) {
1617
1666
  startIndex = Math.min(startIndex, tempStart);
@@ -1624,12 +1673,14 @@
1624
1673
  })();
1625
1674
  }
1626
1675
 
1627
- if (top && (token = this.tokenizer.paragraph(cutSrc))) {
1676
+ if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
1628
1677
  lastToken = tokens[tokens.length - 1];
1629
1678
 
1630
1679
  if (lastParagraphClipped && lastToken.type === 'paragraph') {
1631
1680
  lastToken.raw += '\n' + token.raw;
1632
1681
  lastToken.text += '\n' + token.text;
1682
+ this.inlineQueue.pop();
1683
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1633
1684
  } else {
1634
1685
  tokens.push(token);
1635
1686
  }
@@ -1647,6 +1698,8 @@
1647
1698
  if (lastToken && lastToken.type === 'text') {
1648
1699
  lastToken.raw += '\n' + token.raw;
1649
1700
  lastToken.text += '\n' + token.text;
1701
+ this.inlineQueue.pop();
1702
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1650
1703
  } else {
1651
1704
  tokens.push(token);
1652
1705
  }
@@ -1666,97 +1719,28 @@
1666
1719
  }
1667
1720
  }
1668
1721
 
1722
+ this.state.top = true;
1669
1723
  return tokens;
1670
1724
  };
1671
1725
 
1672
- _proto.inline = function inline(tokens) {
1673
- var i, j, k, l2, row, token;
1674
- var l = tokens.length;
1675
-
1676
- for (i = 0; i < l; i++) {
1677
- token = tokens[i];
1678
-
1679
- switch (token.type) {
1680
- case 'paragraph':
1681
- case 'text':
1682
- case 'heading':
1683
- {
1684
- token.tokens = [];
1685
- this.inlineTokens(token.text, token.tokens);
1686
- break;
1687
- }
1688
-
1689
- case 'table':
1690
- {
1691
- token.tokens = {
1692
- header: [],
1693
- cells: []
1694
- }; // header
1695
-
1696
- l2 = token.header.length;
1697
-
1698
- for (j = 0; j < l2; j++) {
1699
- token.tokens.header[j] = [];
1700
- this.inlineTokens(token.header[j], token.tokens.header[j]);
1701
- } // cells
1702
-
1703
-
1704
- l2 = token.cells.length;
1705
-
1706
- for (j = 0; j < l2; j++) {
1707
- row = token.cells[j];
1708
- token.tokens.cells[j] = [];
1709
-
1710
- for (k = 0; k < row.length; k++) {
1711
- token.tokens.cells[j][k] = [];
1712
- this.inlineTokens(row[k], token.tokens.cells[j][k]);
1713
- }
1714
- }
1715
-
1716
- break;
1717
- }
1718
-
1719
- case 'blockquote':
1720
- {
1721
- this.inline(token.tokens);
1722
- break;
1723
- }
1724
-
1725
- case 'list':
1726
- {
1727
- l2 = token.items.length;
1728
-
1729
- for (j = 0; j < l2; j++) {
1730
- this.inline(token.items[j].tokens);
1731
- }
1732
-
1733
- break;
1734
- }
1735
- }
1736
- }
1737
-
1738
- return tokens;
1726
+ _proto.inline = function inline(src, tokens) {
1727
+ this.inlineQueue.push({
1728
+ src: src,
1729
+ tokens: tokens
1730
+ });
1739
1731
  }
1740
1732
  /**
1741
1733
  * Lexing/Compiling
1742
1734
  */
1743
1735
  ;
1744
1736
 
1745
- _proto.inlineTokens = function inlineTokens(src, tokens, inLink, inRawBlock) {
1737
+ _proto.inlineTokens = function inlineTokens(src, tokens) {
1746
1738
  var _this2 = this;
1747
1739
 
1748
1740
  if (tokens === void 0) {
1749
1741
  tokens = [];
1750
1742
  }
1751
1743
 
1752
- if (inLink === void 0) {
1753
- inLink = false;
1754
- }
1755
-
1756
- if (inRawBlock === void 0) {
1757
- inRawBlock = false;
1758
- }
1759
-
1760
1744
  var token, lastToken, cutSrc; // String with links masked to avoid interference with em and strong
1761
1745
 
1762
1746
  var maskedSrc = src;
@@ -1786,16 +1770,16 @@
1786
1770
  }
1787
1771
 
1788
1772
  while (src) {
1789
- var _this$options2, _this$options2$extens, _this$options$extensi3;
1790
-
1791
1773
  if (!keepPrevChar) {
1792
1774
  prevChar = '';
1793
1775
  }
1794
1776
 
1795
1777
  keepPrevChar = false; // extensions
1796
1778
 
1797
- if ((_this$options2 = this.options) != null && (_this$options2$extens = _this$options2.extensions) != null && _this$options2$extens.inline && this.options.extensions.inline.some(function (extTokenizer) {
1798
- if (token = extTokenizer.call(_this2, src, tokens)) {
1779
+ if (this.options.extensions && this.options.extensions.inline && this.options.extensions.inline.some(function (extTokenizer) {
1780
+ if (token = extTokenizer.call({
1781
+ lexer: _this2
1782
+ }, src, tokens)) {
1799
1783
  src = src.substring(token.raw.length);
1800
1784
  tokens.push(token);
1801
1785
  return true;
@@ -1814,10 +1798,8 @@
1814
1798
  } // tag
1815
1799
 
1816
1800
 
1817
- if (token = this.tokenizer.tag(src, inLink, inRawBlock)) {
1801
+ if (token = this.tokenizer.tag(src)) {
1818
1802
  src = src.substring(token.raw.length);
1819
- inLink = token.inLink;
1820
- inRawBlock = token.inRawBlock;
1821
1803
  lastToken = tokens[tokens.length - 1];
1822
1804
 
1823
1805
  if (lastToken && token.type === 'text' && lastToken.type === 'text') {
@@ -1833,11 +1815,6 @@
1833
1815
 
1834
1816
  if (token = this.tokenizer.link(src)) {
1835
1817
  src = src.substring(token.raw.length);
1836
-
1837
- if (token.type === 'link') {
1838
- token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
1839
- }
1840
-
1841
1818
  tokens.push(token);
1842
1819
  continue;
1843
1820
  } // reflink, nolink
@@ -1847,10 +1824,7 @@
1847
1824
  src = src.substring(token.raw.length);
1848
1825
  lastToken = tokens[tokens.length - 1];
1849
1826
 
1850
- if (token.type === 'link') {
1851
- token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
1852
- tokens.push(token);
1853
- } else if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1827
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1854
1828
  lastToken.raw += token.raw;
1855
1829
  lastToken.text += token.text;
1856
1830
  } else {
@@ -1863,7 +1837,6 @@
1863
1837
 
1864
1838
  if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
1865
1839
  src = src.substring(token.raw.length);
1866
- token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1867
1840
  tokens.push(token);
1868
1841
  continue;
1869
1842
  } // code
@@ -1885,7 +1858,6 @@
1885
1858
 
1886
1859
  if (token = this.tokenizer.del(src)) {
1887
1860
  src = src.substring(token.raw.length);
1888
- token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1889
1861
  tokens.push(token);
1890
1862
  continue;
1891
1863
  } // autolink
@@ -1898,7 +1870,7 @@
1898
1870
  } // url (gfm)
1899
1871
 
1900
1872
 
1901
- if (!inLink && (token = this.tokenizer.url(src, mangle))) {
1873
+ if (!this.state.inLink && (token = this.tokenizer.url(src, mangle))) {
1902
1874
  src = src.substring(token.raw.length);
1903
1875
  tokens.push(token);
1904
1876
  continue;
@@ -1908,14 +1880,16 @@
1908
1880
 
1909
1881
  cutSrc = src;
1910
1882
 
1911
- if ((_this$options$extensi3 = this.options.extensions) != null && _this$options$extensi3.startInline) {
1883
+ if (this.options.extensions && this.options.extensions.startInline) {
1912
1884
  (function () {
1913
1885
  var startIndex = Infinity;
1914
1886
  var tempSrc = src.slice(1);
1915
1887
  var tempStart = void 0;
1916
1888
 
1917
1889
  _this2.options.extensions.startInline.forEach(function (getStartIndex) {
1918
- tempStart = getStartIndex.call(this, tempSrc);
1890
+ tempStart = getStartIndex.call({
1891
+ lexer: this
1892
+ }, tempSrc);
1919
1893
 
1920
1894
  if (typeof tempStart === 'number' && tempStart >= 0) {
1921
1895
  startIndex = Math.min(startIndex, tempStart);
@@ -1928,7 +1902,7 @@
1928
1902
  })();
1929
1903
  }
1930
1904
 
1931
- if (token = this.tokenizer.inlineText(cutSrc, inRawBlock, smartypants)) {
1905
+ if (token = this.tokenizer.inlineText(cutSrc, smartypants)) {
1932
1906
  src = src.substring(token.raw.length);
1933
1907
 
1934
1908
  if (token.raw.slice(-1) !== '_') {
@@ -2309,12 +2283,12 @@
2309
2283
  var l = tokens.length;
2310
2284
 
2311
2285
  for (i = 0; i < l; i++) {
2312
- var _this$options$extensi, _this$options$extensi2;
2313
-
2314
2286
  token = tokens[i]; // Run any renderer extensions
2315
2287
 
2316
- if ((_this$options$extensi = this.options.extensions) != null && (_this$options$extensi2 = _this$options$extensi.renderers) != null && _this$options$extensi2[token.type]) {
2317
- ret = this.options.extensions.renderers[token.type].call(this, token);
2288
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
2289
+ ret = this.options.extensions.renderers[token.type].call({
2290
+ parser: this
2291
+ }, token);
2318
2292
 
2319
2293
  if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(token.type)) {
2320
2294
  out += ret || '';
@@ -2354,7 +2328,7 @@
2354
2328
  l2 = token.header.length;
2355
2329
 
2356
2330
  for (j = 0; j < l2; j++) {
2357
- cell += this.renderer.tablecell(this.parseInline(token.tokens.header[j]), {
2331
+ cell += this.renderer.tablecell(this.parseInline(token.header[j].tokens), {
2358
2332
  header: true,
2359
2333
  align: token.align[j]
2360
2334
  });
@@ -2362,15 +2336,15 @@
2362
2336
 
2363
2337
  header += this.renderer.tablerow(cell);
2364
2338
  body = '';
2365
- l2 = token.cells.length;
2339
+ l2 = token.rows.length;
2366
2340
 
2367
2341
  for (j = 0; j < l2; j++) {
2368
- row = token.tokens.cells[j];
2342
+ row = token.rows[j];
2369
2343
  cell = '';
2370
2344
  l3 = row.length;
2371
2345
 
2372
2346
  for (k = 0; k < l3; k++) {
2373
- cell += this.renderer.tablecell(this.parseInline(row[k]), {
2347
+ cell += this.renderer.tablecell(this.parseInline(row[k].tokens), {
2374
2348
  header: false,
2375
2349
  align: token.align[k]
2376
2350
  });
@@ -2408,7 +2382,7 @@
2408
2382
  checkbox = this.renderer.checkbox(checked);
2409
2383
 
2410
2384
  if (loose) {
2411
- if (item.tokens.length > 0 && item.tokens[0].type === 'text') {
2385
+ if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
2412
2386
  item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
2413
2387
 
2414
2388
  if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
@@ -2489,12 +2463,12 @@
2489
2463
  var l = tokens.length;
2490
2464
 
2491
2465
  for (i = 0; i < l; i++) {
2492
- var _this$options$extensi3, _this$options$extensi4;
2493
-
2494
2466
  token = tokens[i]; // Run any renderer extensions
2495
2467
 
2496
- if ((_this$options$extensi3 = this.options.extensions) != null && (_this$options$extensi4 = _this$options$extensi3.renderers) != null && _this$options$extensi4[token.type]) {
2497
- ret = this.options.extensions.renderers[token.type].call(this, token);
2468
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
2469
+ ret = this.options.extensions.renderers[token.type].call({
2470
+ parser: this
2471
+ }, token);
2498
2472
 
2499
2473
  if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(token.type)) {
2500
2474
  out += ret || '';
@@ -2742,10 +2716,8 @@
2742
2716
  }
2743
2717
 
2744
2718
  if (ext.renderer) {
2745
- var _extensions$renderers;
2746
-
2747
2719
  // Renderer extensions
2748
- var prevRenderer = (_extensions$renderers = extensions.renderers) == null ? void 0 : _extensions$renderers[ext.name];
2720
+ var prevRenderer = extensions.renderers ? extensions.renderers[ext.name] : null;
2749
2721
 
2750
2722
  if (prevRenderer) {
2751
2723
  // Replace extension with func to run new extension but fall back if false
@@ -2898,17 +2870,17 @@
2898
2870
  switch (token.type) {
2899
2871
  case 'table':
2900
2872
  {
2901
- for (var _iterator2 = _createForOfIteratorHelperLoose(token.tokens.header), _step2; !(_step2 = _iterator2()).done;) {
2873
+ for (var _iterator2 = _createForOfIteratorHelperLoose(token.header), _step2; !(_step2 = _iterator2()).done;) {
2902
2874
  var cell = _step2.value;
2903
- marked.walkTokens(cell, callback);
2875
+ marked.walkTokens(cell.tokens, callback);
2904
2876
  }
2905
2877
 
2906
- for (var _iterator3 = _createForOfIteratorHelperLoose(token.tokens.cells), _step3; !(_step3 = _iterator3()).done;) {
2878
+ for (var _iterator3 = _createForOfIteratorHelperLoose(token.rows), _step3; !(_step3 = _iterator3()).done;) {
2907
2879
  var row = _step3.value;
2908
2880
 
2909
2881
  for (var _iterator4 = _createForOfIteratorHelperLoose(row), _step4; !(_step4 = _iterator4()).done;) {
2910
2882
  var _cell = _step4.value;
2911
- marked.walkTokens(_cell, callback);
2883
+ marked.walkTokens(_cell.tokens, callback);
2912
2884
  }
2913
2885
  }
2914
2886
 
@@ -2923,18 +2895,12 @@
2923
2895
 
2924
2896
  default:
2925
2897
  {
2926
- var _marked$defaults, _marked$defaults$exte, _marked$defaults$exte2, _marked$defaults3, _marked$defaults3$ext;
2927
-
2928
- if ((_marked$defaults = marked.defaults) != null && (_marked$defaults$exte = _marked$defaults.extensions) != null && (_marked$defaults$exte2 = _marked$defaults$exte.childTokens) != null && _marked$defaults$exte2[token.type]) {
2929
- var _marked$defaults2;
2930
-
2898
+ if (marked.defaults.extensions && marked.defaults.extensions.childTokens && marked.defaults.extensions.childTokens[token.type]) {
2931
2899
  // Walk any extensions
2932
- (_marked$defaults2 = marked.defaults) == null ? void 0 : _marked$defaults2.extensions.childTokens[token.type].forEach(function (childTokens) {
2900
+ marked.defaults.extensions.childTokens[token.type].forEach(function (childTokens) {
2933
2901
  marked.walkTokens(token[childTokens], callback);
2934
2902
  });
2935
- }
2936
-
2937
- if (token.tokens && !((_marked$defaults3 = marked.defaults) != null && (_marked$defaults3$ext = _marked$defaults3.extensions) != null && _marked$defaults3$ext.childTokens[token.type])) {
2903
+ } else if (token.tokens) {
2938
2904
  marked.walkTokens(token.tokens, callback);
2939
2905
  }
2940
2906
  }