marked 0.8.2 → 1.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
@@ -53,6 +53,7 @@
53
53
  silent: false,
54
54
  smartLists: false,
55
55
  smartypants: false,
56
+ tokenizer: null,
56
57
  xhtml: false
57
58
  };
58
59
  }
@@ -342,6 +343,617 @@
342
343
  checkSanitizeDeprecation: checkSanitizeDeprecation
343
344
  };
344
345
 
346
+ var defaults$1 = defaults.defaults;
347
+ var rtrim$1 = helpers.rtrim,
348
+ splitCells$1 = helpers.splitCells,
349
+ _escape = helpers.escape,
350
+ findClosingBracket$1 = helpers.findClosingBracket;
351
+
352
+ function outputLink(cap, link, raw) {
353
+ var href = link.href;
354
+ var title = link.title ? _escape(link.title) : null;
355
+
356
+ if (cap[0].charAt(0) !== '!') {
357
+ return {
358
+ type: 'link',
359
+ raw: raw,
360
+ href: href,
361
+ title: title,
362
+ text: cap[1]
363
+ };
364
+ } else {
365
+ return {
366
+ type: 'image',
367
+ raw: raw,
368
+ text: _escape(cap[1]),
369
+ href: href,
370
+ title: title
371
+ };
372
+ }
373
+ }
374
+ /**
375
+ * Tokenizer
376
+ */
377
+
378
+
379
+ var Tokenizer_1 = /*#__PURE__*/function () {
380
+ function Tokenizer(options) {
381
+ this.options = options || defaults$1;
382
+ }
383
+
384
+ var _proto = Tokenizer.prototype;
385
+
386
+ _proto.space = function space(src) {
387
+ var cap = this.rules.block.newline.exec(src);
388
+
389
+ if (cap) {
390
+ if (cap[0].length > 1) {
391
+ return {
392
+ type: 'space',
393
+ raw: cap[0]
394
+ };
395
+ }
396
+
397
+ return {
398
+ raw: '\n'
399
+ };
400
+ }
401
+ };
402
+
403
+ _proto.code = function code(src, tokens) {
404
+ var cap = this.rules.block.code.exec(src);
405
+
406
+ if (cap) {
407
+ var lastToken = tokens[tokens.length - 1]; // An indented code block cannot interrupt a paragraph.
408
+
409
+ if (lastToken && lastToken.type === 'paragraph') {
410
+ tokens.pop();
411
+ lastToken.text += '\n' + cap[0].trimRight();
412
+ lastToken.raw += '\n' + cap[0];
413
+ return lastToken;
414
+ } else {
415
+ var text = cap[0].replace(/^ {4}/gm, '');
416
+ return {
417
+ type: 'code',
418
+ raw: cap[0],
419
+ codeBlockStyle: 'indented',
420
+ text: !this.options.pedantic ? rtrim$1(text, '\n') : text
421
+ };
422
+ }
423
+ }
424
+ };
425
+
426
+ _proto.fences = function fences(src) {
427
+ var cap = this.rules.block.fences.exec(src);
428
+
429
+ if (cap) {
430
+ return {
431
+ type: 'code',
432
+ raw: cap[0],
433
+ lang: cap[2] ? cap[2].trim() : cap[2],
434
+ text: cap[3] || ''
435
+ };
436
+ }
437
+ };
438
+
439
+ _proto.heading = function heading(src) {
440
+ var cap = this.rules.block.heading.exec(src);
441
+
442
+ if (cap) {
443
+ return {
444
+ type: 'heading',
445
+ raw: cap[0],
446
+ depth: cap[1].length,
447
+ text: cap[2]
448
+ };
449
+ }
450
+ };
451
+
452
+ _proto.nptable = function nptable(src) {
453
+ var cap = this.rules.block.nptable.exec(src);
454
+
455
+ if (cap) {
456
+ var item = {
457
+ type: 'table',
458
+ header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
459
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
460
+ cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [],
461
+ raw: cap[0]
462
+ };
463
+
464
+ if (item.header.length === item.align.length) {
465
+ var l = item.align.length;
466
+ var i;
467
+
468
+ for (i = 0; i < l; i++) {
469
+ if (/^ *-+: *$/.test(item.align[i])) {
470
+ item.align[i] = 'right';
471
+ } else if (/^ *:-+: *$/.test(item.align[i])) {
472
+ item.align[i] = 'center';
473
+ } else if (/^ *:-+ *$/.test(item.align[i])) {
474
+ item.align[i] = 'left';
475
+ } else {
476
+ item.align[i] = null;
477
+ }
478
+ }
479
+
480
+ l = item.cells.length;
481
+
482
+ for (i = 0; i < l; i++) {
483
+ item.cells[i] = splitCells$1(item.cells[i], item.header.length);
484
+ }
485
+
486
+ return item;
487
+ }
488
+ }
489
+ };
490
+
491
+ _proto.hr = function hr(src) {
492
+ var cap = this.rules.block.hr.exec(src);
493
+
494
+ if (cap) {
495
+ return {
496
+ type: 'hr',
497
+ raw: cap[0]
498
+ };
499
+ }
500
+ };
501
+
502
+ _proto.blockquote = function blockquote(src) {
503
+ var cap = this.rules.block.blockquote.exec(src);
504
+
505
+ if (cap) {
506
+ var text = cap[0].replace(/^ *> ?/gm, '');
507
+ return {
508
+ type: 'blockquote',
509
+ raw: cap[0],
510
+ text: text
511
+ };
512
+ }
513
+ };
514
+
515
+ _proto.list = function list(src) {
516
+ var cap = this.rules.block.list.exec(src);
517
+
518
+ if (cap) {
519
+ var raw = cap[0];
520
+ var bull = cap[2];
521
+ var isordered = bull.length > 1;
522
+ var list = {
523
+ type: 'list',
524
+ raw: raw,
525
+ ordered: isordered,
526
+ start: isordered ? +bull : '',
527
+ loose: false,
528
+ items: []
529
+ }; // Get each top-level item.
530
+
531
+ var itemMatch = cap[0].match(this.rules.block.item);
532
+ var next = false,
533
+ item,
534
+ space,
535
+ b,
536
+ addBack,
537
+ loose,
538
+ istask,
539
+ ischecked;
540
+ var l = itemMatch.length;
541
+
542
+ for (var i = 0; i < l; i++) {
543
+ item = itemMatch[i];
544
+ raw = item; // Remove the list item's bullet
545
+ // so it is seen as the next token.
546
+
547
+ space = item.length;
548
+ item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the
549
+ // list item contains. Hacky.
550
+
551
+ if (~item.indexOf('\n ')) {
552
+ space -= item.length;
553
+ item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, '');
554
+ } // Determine whether the next list item belongs here.
555
+ // Backpedal if it does not belong in this list.
556
+
557
+
558
+ if (i !== l - 1) {
559
+ b = this.rules.block.bullet.exec(itemMatch[i + 1])[0];
560
+
561
+ if (bull.length > 1 ? b.length === 1 : b.length > 1 || this.options.smartLists && b !== bull) {
562
+ addBack = itemMatch.slice(i + 1).join('\n');
563
+ list.raw = list.raw.substring(0, list.raw.length - addBack.length);
564
+ i = l - 1;
565
+ }
566
+ } // Determine whether item is loose or not.
567
+ // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
568
+ // for discount behavior.
569
+
570
+
571
+ loose = next || /\n\n(?!\s*$)/.test(item);
572
+
573
+ if (i !== l - 1) {
574
+ next = item.charAt(item.length - 1) === '\n';
575
+ if (!loose) loose = next;
576
+ }
577
+
578
+ if (loose) {
579
+ list.loose = true;
580
+ } // Check for task list items
581
+
582
+
583
+ istask = /^\[[ xX]\] /.test(item);
584
+ ischecked = undefined;
585
+
586
+ if (istask) {
587
+ ischecked = item[1] !== ' ';
588
+ item = item.replace(/^\[[ xX]\] +/, '');
589
+ }
590
+
591
+ list.items.push({
592
+ raw: raw,
593
+ task: istask,
594
+ checked: ischecked,
595
+ loose: loose,
596
+ text: item
597
+ });
598
+ }
599
+
600
+ return list;
601
+ }
602
+ };
603
+
604
+ _proto.html = function html(src) {
605
+ var cap = this.rules.block.html.exec(src);
606
+
607
+ if (cap) {
608
+ return {
609
+ type: this.options.sanitize ? 'paragraph' : 'html',
610
+ raw: cap[0],
611
+ pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
612
+ text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
613
+ };
614
+ }
615
+ };
616
+
617
+ _proto.def = function def(src) {
618
+ var cap = this.rules.block.def.exec(src);
619
+
620
+ if (cap) {
621
+ if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
622
+ var tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
623
+ return {
624
+ tag: tag,
625
+ raw: cap[0],
626
+ href: cap[2],
627
+ title: cap[3]
628
+ };
629
+ }
630
+ };
631
+
632
+ _proto.table = function table(src) {
633
+ var cap = this.rules.block.table.exec(src);
634
+
635
+ if (cap) {
636
+ var item = {
637
+ type: 'table',
638
+ header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
639
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
640
+ cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
641
+ };
642
+
643
+ if (item.header.length === item.align.length) {
644
+ item.raw = cap[0];
645
+ var l = item.align.length;
646
+ var i;
647
+
648
+ for (i = 0; i < l; i++) {
649
+ if (/^ *-+: *$/.test(item.align[i])) {
650
+ item.align[i] = 'right';
651
+ } else if (/^ *:-+: *$/.test(item.align[i])) {
652
+ item.align[i] = 'center';
653
+ } else if (/^ *:-+ *$/.test(item.align[i])) {
654
+ item.align[i] = 'left';
655
+ } else {
656
+ item.align[i] = null;
657
+ }
658
+ }
659
+
660
+ l = item.cells.length;
661
+
662
+ for (i = 0; i < l; i++) {
663
+ item.cells[i] = splitCells$1(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length);
664
+ }
665
+
666
+ return item;
667
+ }
668
+ }
669
+ };
670
+
671
+ _proto.lheading = function lheading(src) {
672
+ var cap = this.rules.block.lheading.exec(src);
673
+
674
+ if (cap) {
675
+ return {
676
+ type: 'heading',
677
+ raw: cap[0],
678
+ depth: cap[2].charAt(0) === '=' ? 1 : 2,
679
+ text: cap[1]
680
+ };
681
+ }
682
+ };
683
+
684
+ _proto.paragraph = function paragraph(src) {
685
+ var cap = this.rules.block.paragraph.exec(src);
686
+
687
+ if (cap) {
688
+ return {
689
+ type: 'paragraph',
690
+ raw: cap[0],
691
+ text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1]
692
+ };
693
+ }
694
+ };
695
+
696
+ _proto.text = function text(src) {
697
+ var cap = this.rules.block.text.exec(src);
698
+
699
+ if (cap) {
700
+ return {
701
+ type: 'text',
702
+ raw: cap[0],
703
+ text: cap[0]
704
+ };
705
+ }
706
+ };
707
+
708
+ _proto.escape = function escape(src) {
709
+ var cap = this.rules.inline.escape.exec(src);
710
+
711
+ if (cap) {
712
+ return {
713
+ type: 'escape',
714
+ raw: cap[0],
715
+ text: _escape(cap[1])
716
+ };
717
+ }
718
+ };
719
+
720
+ _proto.tag = function tag(src, inLink, inRawBlock) {
721
+ var cap = this.rules.inline.tag.exec(src);
722
+
723
+ if (cap) {
724
+ if (!inLink && /^<a /i.test(cap[0])) {
725
+ inLink = true;
726
+ } else if (inLink && /^<\/a>/i.test(cap[0])) {
727
+ inLink = false;
728
+ }
729
+
730
+ if (!inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
731
+ inRawBlock = true;
732
+ } else if (inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
733
+ inRawBlock = false;
734
+ }
735
+
736
+ return {
737
+ type: this.options.sanitize ? 'text' : 'html',
738
+ raw: cap[0],
739
+ inLink: inLink,
740
+ inRawBlock: inRawBlock,
741
+ text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
742
+ };
743
+ }
744
+ };
745
+
746
+ _proto.link = function link(src) {
747
+ var cap = this.rules.inline.link.exec(src);
748
+
749
+ if (cap) {
750
+ var lastParenIndex = findClosingBracket$1(cap[2], '()');
751
+
752
+ if (lastParenIndex > -1) {
753
+ var start = cap[0].indexOf('!') === 0 ? 5 : 4;
754
+ var linkLen = start + cap[1].length + lastParenIndex;
755
+ cap[2] = cap[2].substring(0, lastParenIndex);
756
+ cap[0] = cap[0].substring(0, linkLen).trim();
757
+ cap[3] = '';
758
+ }
759
+
760
+ var href = cap[2];
761
+ var title = '';
762
+
763
+ if (this.options.pedantic) {
764
+ var link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
765
+
766
+ if (link) {
767
+ href = link[1];
768
+ title = link[3];
769
+ } else {
770
+ title = '';
771
+ }
772
+ } else {
773
+ title = cap[3] ? cap[3].slice(1, -1) : '';
774
+ }
775
+
776
+ href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
777
+ var token = outputLink(cap, {
778
+ href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
779
+ title: title ? title.replace(this.rules.inline._escapes, '$1') : title
780
+ }, cap[0]);
781
+ return token;
782
+ }
783
+ };
784
+
785
+ _proto.reflink = function reflink(src, links) {
786
+ var cap;
787
+
788
+ if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
789
+ var link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
790
+ link = links[link.toLowerCase()];
791
+
792
+ if (!link || !link.href) {
793
+ var text = cap[0].charAt(0);
794
+ return {
795
+ type: 'text',
796
+ raw: text,
797
+ text: text
798
+ };
799
+ }
800
+
801
+ var token = outputLink(cap, link, cap[0]);
802
+ return token;
803
+ }
804
+ };
805
+
806
+ _proto.strong = function strong(src) {
807
+ var cap = this.rules.inline.strong.exec(src);
808
+
809
+ if (cap) {
810
+ return {
811
+ type: 'strong',
812
+ raw: cap[0],
813
+ text: cap[4] || cap[3] || cap[2] || cap[1]
814
+ };
815
+ }
816
+ };
817
+
818
+ _proto.em = function em(src) {
819
+ var cap = this.rules.inline.em.exec(src);
820
+
821
+ if (cap) {
822
+ return {
823
+ type: 'em',
824
+ raw: cap[0],
825
+ text: cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]
826
+ };
827
+ }
828
+ };
829
+
830
+ _proto.codespan = function codespan(src) {
831
+ var cap = this.rules.inline.code.exec(src);
832
+
833
+ if (cap) {
834
+ return {
835
+ type: 'codespan',
836
+ raw: cap[0],
837
+ text: _escape(cap[2].trim(), true)
838
+ };
839
+ }
840
+ };
841
+
842
+ _proto.br = function br(src) {
843
+ var cap = this.rules.inline.br.exec(src);
844
+
845
+ if (cap) {
846
+ return {
847
+ type: 'br',
848
+ raw: cap[0]
849
+ };
850
+ }
851
+ };
852
+
853
+ _proto.del = function del(src) {
854
+ var cap = this.rules.inline.del.exec(src);
855
+
856
+ if (cap) {
857
+ return {
858
+ type: 'del',
859
+ raw: cap[0],
860
+ text: cap[1]
861
+ };
862
+ }
863
+ };
864
+
865
+ _proto.autolink = function autolink(src, mangle) {
866
+ var cap = this.rules.inline.autolink.exec(src);
867
+
868
+ if (cap) {
869
+ var text, href;
870
+
871
+ if (cap[2] === '@') {
872
+ text = _escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
873
+ href = 'mailto:' + text;
874
+ } else {
875
+ text = _escape(cap[1]);
876
+ href = text;
877
+ }
878
+
879
+ return {
880
+ type: 'link',
881
+ raw: cap[0],
882
+ text: text,
883
+ href: href,
884
+ tokens: [{
885
+ type: 'text',
886
+ raw: text,
887
+ text: text
888
+ }]
889
+ };
890
+ }
891
+ };
892
+
893
+ _proto.url = function url(src, mangle) {
894
+ var cap;
895
+
896
+ if (cap = this.rules.inline.url.exec(src)) {
897
+ var text, href;
898
+
899
+ if (cap[2] === '@') {
900
+ text = _escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
901
+ href = 'mailto:' + text;
902
+ } else {
903
+ // do extended autolink path validation
904
+ var prevCapZero;
905
+
906
+ do {
907
+ prevCapZero = cap[0];
908
+ cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
909
+ } while (prevCapZero !== cap[0]);
910
+
911
+ text = _escape(cap[0]);
912
+
913
+ if (cap[1] === 'www.') {
914
+ href = 'http://' + text;
915
+ } else {
916
+ href = text;
917
+ }
918
+ }
919
+
920
+ return {
921
+ type: 'link',
922
+ raw: cap[0],
923
+ text: text,
924
+ href: href,
925
+ tokens: [{
926
+ type: 'text',
927
+ raw: text,
928
+ text: text
929
+ }]
930
+ };
931
+ }
932
+ };
933
+
934
+ _proto.inlineText = function inlineText(src, inRawBlock, smartypants) {
935
+ var cap = this.rules.inline.text.exec(src);
936
+
937
+ if (cap) {
938
+ var text;
939
+
940
+ if (inRawBlock) {
941
+ text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0];
942
+ } else {
943
+ text = _escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
944
+ }
945
+
946
+ return {
947
+ type: 'text',
948
+ raw: cap[0],
949
+ text: text
950
+ };
951
+ }
952
+ };
953
+
954
+ return Tokenizer;
955
+ }();
956
+
345
957
  var noopTest$1 = helpers.noopTest,
346
958
  edit$1 = helpers.edit,
347
959
  merge$1 = helpers.merge;
@@ -447,7 +1059,7 @@
447
1059
  reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
448
1060
  nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
449
1061
  strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
450
- em: /^_([^\s_])_(?!_)|^\*([^\s*<\[])\*(?!\*)|^_([^\s<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s<"][\s\S]*?[^\s\*])\*(?!\*|[^\spunctuation])|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
1062
+ em: /^_([^\s_])_(?!_)|^_([^\s_<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s*<\[])\*(?!\*)|^\*([^\s<"][\s\S]*?[^\s\[\*])\*(?![\]`punctuation])|^\*([^\s*"<\[][\s\S]*[^\s])\*(?!\*)/,
451
1063
  code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
452
1064
  br: /^( {2,}|\\)\n(?!\s*$)/,
453
1065
  del: noopTest$1,
@@ -455,7 +1067,7 @@
455
1067
  }; // list of punctuation marks from common mark spec
456
1068
  // without ` and ] to workaround Rule 17 (inline code blocks/links)
457
1069
 
458
- inline._punctuation = '!"#$%&\'()*+,\\-./:;<=>?@\\[^_{|}~';
1070
+ inline._punctuation = '!"#$%&\'()*+\\-./:;<=>?@\\[^_{|}~';
459
1071
  inline.em = edit$1(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
460
1072
  inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
461
1073
  inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
@@ -509,30 +1121,81 @@
509
1121
  inline: inline
510
1122
  };
511
1123
 
512
- var defaults$1 = defaults.defaults;
513
- var block$1 = rules.block;
514
- var rtrim$1 = helpers.rtrim,
515
- splitCells$1 = helpers.splitCells,
516
- escape$1 = helpers.escape;
1124
+ var defaults$2 = defaults.defaults;
1125
+ var block$1 = rules.block,
1126
+ inline$1 = rules.inline;
517
1127
  /**
518
- * Block Lexer
1128
+ * smartypants text replacement
519
1129
  */
520
1130
 
521
- var Lexer_1 = /*#__PURE__*/function () {
1131
+ function smartypants(text) {
1132
+ return text // em-dashes
1133
+ .replace(/---/g, "\u2014") // en-dashes
1134
+ .replace(/--/g, "\u2013") // opening singles
1135
+ .replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // closing singles & apostrophes
1136
+ .replace(/'/g, "\u2019") // opening doubles
1137
+ .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C") // closing doubles
1138
+ .replace(/"/g, "\u201D") // ellipses
1139
+ .replace(/\.{3}/g, "\u2026");
1140
+ }
1141
+ /**
1142
+ * mangle email addresses
1143
+ */
1144
+
1145
+
1146
+ function mangle(text) {
1147
+ var out = '',
1148
+ i,
1149
+ ch;
1150
+ var l = text.length;
1151
+
1152
+ for (i = 0; i < l; i++) {
1153
+ ch = text.charCodeAt(i);
1154
+
1155
+ if (Math.random() > 0.5) {
1156
+ ch = 'x' + ch.toString(16);
1157
+ }
1158
+
1159
+ out += '&#' + ch + ';';
1160
+ }
1161
+
1162
+ return out;
1163
+ }
1164
+ /**
1165
+ * Block Lexer
1166
+ */
1167
+
1168
+
1169
+ var Lexer_1 = /*#__PURE__*/function () {
522
1170
  function Lexer(options) {
523
1171
  this.tokens = [];
524
1172
  this.tokens.links = Object.create(null);
525
- this.options = options || defaults$1;
526
- this.rules = block$1.normal;
1173
+ this.options = options || defaults$2;
1174
+ this.options.tokenizer = this.options.tokenizer || new Tokenizer_1();
1175
+ this.tokenizer = this.options.tokenizer;
1176
+ this.tokenizer.options = this.options;
1177
+ var rules = {
1178
+ block: block$1.normal,
1179
+ inline: inline$1.normal
1180
+ };
527
1181
 
528
1182
  if (this.options.pedantic) {
529
- this.rules = block$1.pedantic;
1183
+ rules.block = block$1.pedantic;
1184
+ rules.inline = inline$1.pedantic;
530
1185
  } else if (this.options.gfm) {
531
- this.rules = block$1.gfm;
1186
+ rules.block = block$1.gfm;
1187
+
1188
+ if (this.options.breaks) {
1189
+ rules.inline = inline$1.breaks;
1190
+ } else {
1191
+ rules.inline = inline$1.gfm;
1192
+ }
532
1193
  }
1194
+
1195
+ this.tokenizer.rules = rules;
533
1196
  }
534
1197
  /**
535
- * Expose Block Rules
1198
+ * Expose Rules
536
1199
  */
537
1200
 
538
1201
 
@@ -542,353 +1205,395 @@
542
1205
  Lexer.lex = function lex(src, options) {
543
1206
  var lexer = new Lexer(options);
544
1207
  return lexer.lex(src);
545
- };
546
-
547
- var _proto = Lexer.prototype;
548
-
1208
+ }
549
1209
  /**
550
1210
  * Preprocessing
551
1211
  */
1212
+ ;
1213
+
1214
+ var _proto = Lexer.prototype;
1215
+
552
1216
  _proto.lex = function lex(src) {
553
1217
  src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ');
554
- return this.token(src, true);
555
- };
556
-
1218
+ this.blockTokens(src, this.tokens, true);
1219
+ this.inline(this.tokens);
1220
+ return this.tokens;
1221
+ }
557
1222
  /**
558
1223
  * Lexing
559
1224
  */
560
- _proto.token = function token(src, top) {
1225
+ ;
1226
+
1227
+ _proto.blockTokens = function blockTokens(src, tokens, top) {
1228
+ if (tokens === void 0) {
1229
+ tokens = [];
1230
+ }
1231
+
1232
+ if (top === void 0) {
1233
+ top = true;
1234
+ }
1235
+
561
1236
  src = src.replace(/^ +$/gm, '');
562
- var next, loose, cap, bull, b, item, listStart, listItems, t, space, i, tag, l, isordered, istask, ischecked;
1237
+ var token, i, l;
563
1238
 
564
1239
  while (src) {
565
1240
  // newline
566
- if (cap = this.rules.newline.exec(src)) {
567
- src = src.substring(cap[0].length);
1241
+ if (token = this.tokenizer.space(src)) {
1242
+ src = src.substring(token.raw.length);
568
1243
 
569
- if (cap[0].length > 1) {
570
- this.tokens.push({
571
- type: 'space'
572
- });
1244
+ if (token.type) {
1245
+ tokens.push(token);
573
1246
  }
574
- } // code
575
1247
 
1248
+ continue;
1249
+ } // code
576
1250
 
577
- if (cap = this.rules.code.exec(src)) {
578
- var lastToken = this.tokens[this.tokens.length - 1];
579
- src = src.substring(cap[0].length); // An indented code block cannot interrupt a paragraph.
580
-
581
- if (lastToken && lastToken.type === 'paragraph') {
582
- lastToken.text += '\n' + cap[0].trimRight();
583
- } else {
584
- cap = cap[0].replace(/^ {4}/gm, '');
585
- this.tokens.push({
586
- type: 'code',
587
- codeBlockStyle: 'indented',
588
- text: !this.options.pedantic ? rtrim$1(cap, '\n') : cap
589
- });
590
- }
591
1251
 
1252
+ if (token = this.tokenizer.code(src, tokens)) {
1253
+ src = src.substring(token.raw.length);
1254
+ tokens.push(token);
592
1255
  continue;
593
1256
  } // fences
594
1257
 
595
1258
 
596
- if (cap = this.rules.fences.exec(src)) {
597
- src = src.substring(cap[0].length);
598
- this.tokens.push({
599
- type: 'code',
600
- lang: cap[2] ? cap[2].trim() : cap[2],
601
- text: cap[3] || ''
602
- });
1259
+ if (token = this.tokenizer.fences(src)) {
1260
+ src = src.substring(token.raw.length);
1261
+ tokens.push(token);
603
1262
  continue;
604
1263
  } // heading
605
1264
 
606
1265
 
607
- if (cap = this.rules.heading.exec(src)) {
608
- src = src.substring(cap[0].length);
609
- this.tokens.push({
610
- type: 'heading',
611
- depth: cap[1].length,
612
- text: cap[2]
613
- });
1266
+ if (token = this.tokenizer.heading(src)) {
1267
+ src = src.substring(token.raw.length);
1268
+ tokens.push(token);
614
1269
  continue;
615
1270
  } // table no leading pipe (gfm)
616
1271
 
617
1272
 
618
- if (cap = this.rules.nptable.exec(src)) {
619
- item = {
620
- type: 'table',
621
- header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
622
- align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
623
- cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
624
- };
1273
+ if (token = this.tokenizer.nptable(src)) {
1274
+ src = src.substring(token.raw.length);
1275
+ tokens.push(token);
1276
+ continue;
1277
+ } // hr
625
1278
 
626
- if (item.header.length === item.align.length) {
627
- src = src.substring(cap[0].length);
628
1279
 
629
- for (i = 0; i < item.align.length; i++) {
630
- if (/^ *-+: *$/.test(item.align[i])) {
631
- item.align[i] = 'right';
632
- } else if (/^ *:-+: *$/.test(item.align[i])) {
633
- item.align[i] = 'center';
634
- } else if (/^ *:-+ *$/.test(item.align[i])) {
635
- item.align[i] = 'left';
636
- } else {
637
- item.align[i] = null;
638
- }
639
- }
1280
+ if (token = this.tokenizer.hr(src)) {
1281
+ src = src.substring(token.raw.length);
1282
+ tokens.push(token);
1283
+ continue;
1284
+ } // blockquote
1285
+
1286
+
1287
+ if (token = this.tokenizer.blockquote(src)) {
1288
+ src = src.substring(token.raw.length);
1289
+ token.tokens = this.blockTokens(token.text, [], top);
1290
+ tokens.push(token);
1291
+ continue;
1292
+ } // list
640
1293
 
641
- for (i = 0; i < item.cells.length; i++) {
642
- item.cells[i] = splitCells$1(item.cells[i], item.header.length);
643
- }
644
1294
 
645
- this.tokens.push(item);
646
- continue;
1295
+ if (token = this.tokenizer.list(src)) {
1296
+ src = src.substring(token.raw.length);
1297
+ l = token.items.length;
1298
+
1299
+ for (i = 0; i < l; i++) {
1300
+ token.items[i].tokens = this.blockTokens(token.items[i].text, [], false);
647
1301
  }
648
- } // hr
1302
+
1303
+ tokens.push(token);
1304
+ continue;
1305
+ } // html
649
1306
 
650
1307
 
651
- if (cap = this.rules.hr.exec(src)) {
652
- src = src.substring(cap[0].length);
653
- this.tokens.push({
654
- type: 'hr'
655
- });
1308
+ if (token = this.tokenizer.html(src)) {
1309
+ src = src.substring(token.raw.length);
1310
+ tokens.push(token);
656
1311
  continue;
657
- } // blockquote
1312
+ } // def
658
1313
 
659
1314
 
660
- if (cap = this.rules.blockquote.exec(src)) {
661
- src = src.substring(cap[0].length);
662
- this.tokens.push({
663
- type: 'blockquote_start'
664
- });
665
- cap = cap[0].replace(/^ *> ?/gm, ''); // Pass `top` to keep the current
666
- // "toplevel" state. This is exactly
667
- // how markdown.pl works.
1315
+ if (top && (token = this.tokenizer.def(src))) {
1316
+ src = src.substring(token.raw.length);
1317
+
1318
+ if (!this.tokens.links[token.tag]) {
1319
+ this.tokens.links[token.tag] = {
1320
+ href: token.href,
1321
+ title: token.title
1322
+ };
1323
+ }
668
1324
 
669
- this.token(cap, top);
670
- this.tokens.push({
671
- type: 'blockquote_end'
672
- });
673
1325
  continue;
674
- } // list
1326
+ } // table (gfm)
675
1327
 
676
1328
 
677
- if (cap = this.rules.list.exec(src)) {
678
- src = src.substring(cap[0].length);
679
- bull = cap[2];
680
- isordered = bull.length > 1;
681
- listStart = {
682
- type: 'list_start',
683
- ordered: isordered,
684
- start: isordered ? +bull : '',
685
- loose: false
686
- };
687
- this.tokens.push(listStart); // Get each top-level item.
1329
+ if (token = this.tokenizer.table(src)) {
1330
+ src = src.substring(token.raw.length);
1331
+ tokens.push(token);
1332
+ continue;
1333
+ } // lheading
688
1334
 
689
- cap = cap[0].match(this.rules.item);
690
- listItems = [];
691
- next = false;
692
- l = cap.length;
693
- i = 0;
694
1335
 
695
- for (; i < l; i++) {
696
- item = cap[i]; // Remove the list item's bullet
697
- // so it is seen as the next token.
1336
+ if (token = this.tokenizer.lheading(src)) {
1337
+ src = src.substring(token.raw.length);
1338
+ tokens.push(token);
1339
+ continue;
1340
+ } // top-level paragraph
698
1341
 
699
- space = item.length;
700
- item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the
701
- // list item contains. Hacky.
702
1342
 
703
- if (~item.indexOf('\n ')) {
704
- space -= item.length;
705
- item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, '');
706
- } // Determine whether the next list item belongs here.
707
- // Backpedal if it does not belong in this list.
1343
+ if (top && (token = this.tokenizer.paragraph(src))) {
1344
+ src = src.substring(token.raw.length);
1345
+ tokens.push(token);
1346
+ continue;
1347
+ } // text
708
1348
 
709
1349
 
710
- if (i !== l - 1) {
711
- b = block$1.bullet.exec(cap[i + 1])[0];
1350
+ if (token = this.tokenizer.text(src)) {
1351
+ src = src.substring(token.raw.length);
1352
+ tokens.push(token);
1353
+ continue;
1354
+ }
712
1355
 
713
- if (bull.length > 1 ? b.length === 1 : b.length > 1 || this.options.smartLists && b !== bull) {
714
- src = cap.slice(i + 1).join('\n') + src;
715
- i = l - 1;
716
- }
717
- } // Determine whether item is loose or not.
718
- // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
719
- // for discount behavior.
1356
+ if (src) {
1357
+ var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
720
1358
 
1359
+ if (this.options.silent) {
1360
+ console.error(errMsg);
1361
+ break;
1362
+ } else {
1363
+ throw new Error(errMsg);
1364
+ }
1365
+ }
1366
+ }
721
1367
 
722
- loose = next || /\n\n(?!\s*$)/.test(item);
1368
+ return tokens;
1369
+ };
723
1370
 
724
- if (i !== l - 1) {
725
- next = item.charAt(item.length - 1) === '\n';
726
- if (!loose) loose = next;
1371
+ _proto.inline = function inline(tokens) {
1372
+ var i, j, k, l2, row, token;
1373
+ var l = tokens.length;
1374
+
1375
+ for (i = 0; i < l; i++) {
1376
+ token = tokens[i];
1377
+
1378
+ switch (token.type) {
1379
+ case 'paragraph':
1380
+ case 'text':
1381
+ case 'heading':
1382
+ {
1383
+ token.tokens = [];
1384
+ this.inlineTokens(token.text, token.tokens);
1385
+ break;
727
1386
  }
728
1387
 
729
- if (loose) {
730
- listStart.loose = true;
731
- } // Check for task list items
1388
+ case 'table':
1389
+ {
1390
+ token.tokens = {
1391
+ header: [],
1392
+ cells: []
1393
+ }; // header
1394
+
1395
+ l2 = token.header.length;
1396
+
1397
+ for (j = 0; j < l2; j++) {
1398
+ token.tokens.header[j] = [];
1399
+ this.inlineTokens(token.header[j], token.tokens.header[j]);
1400
+ } // cells
1401
+
732
1402
 
1403
+ l2 = token.cells.length;
733
1404
 
734
- istask = /^\[[ xX]\] /.test(item);
735
- ischecked = undefined;
1405
+ for (j = 0; j < l2; j++) {
1406
+ row = token.cells[j];
1407
+ token.tokens.cells[j] = [];
1408
+
1409
+ for (k = 0; k < row.length; k++) {
1410
+ token.tokens.cells[j][k] = [];
1411
+ this.inlineTokens(row[k], token.tokens.cells[j][k]);
1412
+ }
1413
+ }
736
1414
 
737
- if (istask) {
738
- ischecked = item[1] !== ' ';
739
- item = item.replace(/^\[[ xX]\] +/, '');
1415
+ break;
740
1416
  }
741
1417
 
742
- t = {
743
- type: 'list_item_start',
744
- task: istask,
745
- checked: ischecked,
746
- loose: loose
747
- };
748
- listItems.push(t);
749
- this.tokens.push(t); // Recurse.
1418
+ case 'blockquote':
1419
+ {
1420
+ this.inline(token.tokens);
1421
+ break;
1422
+ }
750
1423
 
751
- this.token(item, false);
752
- this.tokens.push({
753
- type: 'list_item_end'
754
- });
755
- }
1424
+ case 'list':
1425
+ {
1426
+ l2 = token.items.length;
756
1427
 
757
- if (listStart.loose) {
758
- l = listItems.length;
759
- i = 0;
1428
+ for (j = 0; j < l2; j++) {
1429
+ this.inline(token.items[j].tokens);
1430
+ }
760
1431
 
761
- for (; i < l; i++) {
762
- listItems[i].loose = true;
1432
+ break;
763
1433
  }
764
- }
1434
+ }
1435
+ }
765
1436
 
766
- this.tokens.push({
767
- type: 'list_end'
768
- });
1437
+ return tokens;
1438
+ }
1439
+ /**
1440
+ * Lexing/Compiling
1441
+ */
1442
+ ;
1443
+
1444
+ _proto.inlineTokens = function inlineTokens(src, tokens, inLink, inRawBlock) {
1445
+ if (tokens === void 0) {
1446
+ tokens = [];
1447
+ }
1448
+
1449
+ if (inLink === void 0) {
1450
+ inLink = false;
1451
+ }
1452
+
1453
+ if (inRawBlock === void 0) {
1454
+ inRawBlock = false;
1455
+ }
1456
+
1457
+ var token;
1458
+
1459
+ while (src) {
1460
+ // escape
1461
+ if (token = this.tokenizer.escape(src)) {
1462
+ src = src.substring(token.raw.length);
1463
+ tokens.push(token);
769
1464
  continue;
770
- } // html
1465
+ } // tag
771
1466
 
772
1467
 
773
- if (cap = this.rules.html.exec(src)) {
774
- src = src.substring(cap[0].length);
775
- this.tokens.push({
776
- type: this.options.sanitize ? 'paragraph' : 'html',
777
- pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
778
- text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$1(cap[0]) : cap[0]
779
- });
1468
+ if (token = this.tokenizer.tag(src, inLink, inRawBlock)) {
1469
+ src = src.substring(token.raw.length);
1470
+ inLink = token.inLink;
1471
+ inRawBlock = token.inRawBlock;
1472
+ tokens.push(token);
780
1473
  continue;
781
- } // def
1474
+ } // link
782
1475
 
783
1476
 
784
- if (top && (cap = this.rules.def.exec(src))) {
785
- src = src.substring(cap[0].length);
786
- if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
787
- tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
1477
+ if (token = this.tokenizer.link(src)) {
1478
+ src = src.substring(token.raw.length);
788
1479
 
789
- if (!this.tokens.links[tag]) {
790
- this.tokens.links[tag] = {
791
- href: cap[2],
792
- title: cap[3]
793
- };
1480
+ if (token.type === 'link') {
1481
+ token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
794
1482
  }
795
1483
 
1484
+ tokens.push(token);
796
1485
  continue;
797
- } // table (gfm)
1486
+ } // reflink, nolink
798
1487
 
799
1488
 
800
- if (cap = this.rules.table.exec(src)) {
801
- item = {
802
- type: 'table',
803
- header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
804
- align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
805
- cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
806
- };
1489
+ if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1490
+ src = src.substring(token.raw.length);
807
1491
 
808
- if (item.header.length === item.align.length) {
809
- src = src.substring(cap[0].length);
1492
+ if (token.type === 'link') {
1493
+ token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
1494
+ }
810
1495
 
811
- for (i = 0; i < item.align.length; i++) {
812
- if (/^ *-+: *$/.test(item.align[i])) {
813
- item.align[i] = 'right';
814
- } else if (/^ *:-+: *$/.test(item.align[i])) {
815
- item.align[i] = 'center';
816
- } else if (/^ *:-+ *$/.test(item.align[i])) {
817
- item.align[i] = 'left';
818
- } else {
819
- item.align[i] = null;
820
- }
821
- }
1496
+ tokens.push(token);
1497
+ continue;
1498
+ } // strong
822
1499
 
823
- for (i = 0; i < item.cells.length; i++) {
824
- item.cells[i] = splitCells$1(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length);
825
- }
826
1500
 
827
- this.tokens.push(item);
828
- continue;
829
- }
830
- } // lheading
1501
+ if (token = this.tokenizer.strong(src)) {
1502
+ src = src.substring(token.raw.length);
1503
+ token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1504
+ tokens.push(token);
1505
+ continue;
1506
+ } // em
831
1507
 
832
1508
 
833
- if (cap = this.rules.lheading.exec(src)) {
834
- src = src.substring(cap[0].length);
835
- this.tokens.push({
836
- type: 'heading',
837
- depth: cap[2].charAt(0) === '=' ? 1 : 2,
838
- text: cap[1]
839
- });
1509
+ if (token = this.tokenizer.em(src)) {
1510
+ src = src.substring(token.raw.length);
1511
+ token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1512
+ tokens.push(token);
840
1513
  continue;
841
- } // top-level paragraph
1514
+ } // code
842
1515
 
843
1516
 
844
- if (top && (cap = this.rules.paragraph.exec(src))) {
845
- src = src.substring(cap[0].length);
846
- this.tokens.push({
847
- type: 'paragraph',
848
- text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1]
849
- });
1517
+ if (token = this.tokenizer.codespan(src)) {
1518
+ src = src.substring(token.raw.length);
1519
+ tokens.push(token);
1520
+ continue;
1521
+ } // br
1522
+
1523
+
1524
+ if (token = this.tokenizer.br(src)) {
1525
+ src = src.substring(token.raw.length);
1526
+ tokens.push(token);
1527
+ continue;
1528
+ } // del (gfm)
1529
+
1530
+
1531
+ if (token = this.tokenizer.del(src)) {
1532
+ src = src.substring(token.raw.length);
1533
+ token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1534
+ tokens.push(token);
1535
+ continue;
1536
+ } // autolink
1537
+
1538
+
1539
+ if (token = this.tokenizer.autolink(src, mangle)) {
1540
+ src = src.substring(token.raw.length);
1541
+ tokens.push(token);
1542
+ continue;
1543
+ } // url (gfm)
1544
+
1545
+
1546
+ if (!inLink && (token = this.tokenizer.url(src, mangle))) {
1547
+ src = src.substring(token.raw.length);
1548
+ tokens.push(token);
850
1549
  continue;
851
1550
  } // text
852
1551
 
853
1552
 
854
- if (cap = this.rules.text.exec(src)) {
855
- // Top-level should never reach here.
856
- src = src.substring(cap[0].length);
857
- this.tokens.push({
858
- type: 'text',
859
- text: cap[0]
860
- });
1553
+ if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) {
1554
+ src = src.substring(token.raw.length);
1555
+ tokens.push(token);
861
1556
  continue;
862
1557
  }
863
1558
 
864
1559
  if (src) {
865
- throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
1560
+ var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1561
+
1562
+ if (this.options.silent) {
1563
+ console.error(errMsg);
1564
+ break;
1565
+ } else {
1566
+ throw new Error(errMsg);
1567
+ }
866
1568
  }
867
1569
  }
868
1570
 
869
- return this.tokens;
1571
+ return tokens;
870
1572
  };
871
1573
 
872
1574
  _createClass(Lexer, null, [{
873
1575
  key: "rules",
874
1576
  get: function get() {
875
- return block$1;
1577
+ return {
1578
+ block: block$1,
1579
+ inline: inline$1
1580
+ };
876
1581
  }
877
1582
  }]);
878
1583
 
879
1584
  return Lexer;
880
1585
  }();
881
1586
 
882
- var defaults$2 = defaults.defaults;
1587
+ var defaults$3 = defaults.defaults;
883
1588
  var cleanUrl$1 = helpers.cleanUrl,
884
- escape$2 = helpers.escape;
1589
+ escape$1 = helpers.escape;
885
1590
  /**
886
1591
  * Renderer
887
1592
  */
888
1593
 
889
1594
  var Renderer_1 = /*#__PURE__*/function () {
890
1595
  function Renderer(options) {
891
- this.options = options || defaults$2;
1596
+ this.options = options || defaults$3;
892
1597
  }
893
1598
 
894
1599
  var _proto = Renderer.prototype;
@@ -906,10 +1611,10 @@
906
1611
  }
907
1612
 
908
1613
  if (!lang) {
909
- return '<pre><code>' + (escaped ? _code : escape$2(_code, true)) + '</code></pre>';
1614
+ return '<pre><code>' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>';
910
1615
  }
911
1616
 
912
- return '<pre><code class="' + this.options.langPrefix + escape$2(lang, true) + '">' + (escaped ? _code : escape$2(_code, true)) + '</code></pre>\n';
1617
+ return '<pre><code class="' + this.options.langPrefix + escape$1(lang, true) + '">' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>\n';
913
1618
  };
914
1619
 
915
1620
  _proto.blockquote = function blockquote(quote) {
@@ -934,437 +1639,98 @@
934
1639
  };
935
1640
 
936
1641
  _proto.list = function list(body, ordered, start) {
937
- var type = ordered ? 'ol' : 'ul',
938
- startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
939
- return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
940
- };
941
-
942
- _proto.listitem = function listitem(text) {
943
- return '<li>' + text + '</li>\n';
944
- };
945
-
946
- _proto.checkbox = function checkbox(checked) {
947
- return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
948
- };
949
-
950
- _proto.paragraph = function paragraph(text) {
951
- return '<p>' + text + '</p>\n';
952
- };
953
-
954
- _proto.table = function table(header, body) {
955
- if (body) body = '<tbody>' + body + '</tbody>';
956
- return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
957
- };
958
-
959
- _proto.tablerow = function tablerow(content) {
960
- return '<tr>\n' + content + '</tr>\n';
961
- };
962
-
963
- _proto.tablecell = function tablecell(content, flags) {
964
- var type = flags.header ? 'th' : 'td';
965
- var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>';
966
- return tag + content + '</' + type + '>\n';
967
- };
968
-
969
- // span level renderer
970
- _proto.strong = function strong(text) {
971
- return '<strong>' + text + '</strong>';
972
- };
973
-
974
- _proto.em = function em(text) {
975
- return '<em>' + text + '</em>';
976
- };
977
-
978
- _proto.codespan = function codespan(text) {
979
- return '<code>' + text + '</code>';
980
- };
981
-
982
- _proto.br = function br() {
983
- return this.options.xhtml ? '<br/>' : '<br>';
984
- };
985
-
986
- _proto.del = function del(text) {
987
- return '<del>' + text + '</del>';
988
- };
989
-
990
- _proto.link = function link(href, title, text) {
991
- href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
992
-
993
- if (href === null) {
994
- return text;
995
- }
996
-
997
- var out = '<a href="' + escape$2(href) + '"';
998
-
999
- if (title) {
1000
- out += ' title="' + title + '"';
1001
- }
1002
-
1003
- out += '>' + text + '</a>';
1004
- return out;
1005
- };
1006
-
1007
- _proto.image = function image(href, title, text) {
1008
- href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
1009
-
1010
- if (href === null) {
1011
- return text;
1012
- }
1013
-
1014
- var out = '<img src="' + href + '" alt="' + text + '"';
1015
-
1016
- if (title) {
1017
- out += ' title="' + title + '"';
1018
- }
1019
-
1020
- out += this.options.xhtml ? '/>' : '>';
1021
- return out;
1022
- };
1023
-
1024
- _proto.text = function text(_text) {
1025
- return _text;
1026
- };
1027
-
1028
- return Renderer;
1029
- }();
1030
-
1031
- /**
1032
- * Slugger generates header id
1033
- */
1034
- var Slugger_1 = /*#__PURE__*/function () {
1035
- function Slugger() {
1036
- this.seen = {};
1037
- }
1038
- /**
1039
- * Convert string to unique id
1040
- */
1041
-
1042
-
1043
- var _proto = Slugger.prototype;
1044
-
1045
- _proto.slug = function slug(value) {
1046
- var slug = value.toLowerCase().trim() // remove html tags
1047
- .replace(/<[!\/a-z].*?>/ig, '') // remove unwanted chars
1048
- .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
1049
-
1050
- if (this.seen.hasOwnProperty(slug)) {
1051
- var originalSlug = slug;
1052
-
1053
- do {
1054
- this.seen[originalSlug]++;
1055
- slug = originalSlug + '-' + this.seen[originalSlug];
1056
- } while (this.seen.hasOwnProperty(slug));
1057
- }
1058
-
1059
- this.seen[slug] = 0;
1060
- return slug;
1061
- };
1062
-
1063
- return Slugger;
1064
- }();
1065
-
1066
- var defaults$3 = defaults.defaults;
1067
- var inline$1 = rules.inline;
1068
- var findClosingBracket$1 = helpers.findClosingBracket,
1069
- escape$3 = helpers.escape;
1070
- /**
1071
- * Inline Lexer & Compiler
1072
- */
1073
-
1074
- var InlineLexer_1 = /*#__PURE__*/function () {
1075
- function InlineLexer(links, options) {
1076
- this.options = options || defaults$3;
1077
- this.links = links;
1078
- this.rules = inline$1.normal;
1079
- this.options.renderer = this.options.renderer || new Renderer_1();
1080
- this.renderer = this.options.renderer;
1081
- this.renderer.options = this.options;
1082
-
1083
- if (!this.links) {
1084
- throw new Error('Tokens array requires a `links` property.');
1085
- }
1086
-
1087
- if (this.options.pedantic) {
1088
- this.rules = inline$1.pedantic;
1089
- } else if (this.options.gfm) {
1090
- if (this.options.breaks) {
1091
- this.rules = inline$1.breaks;
1092
- } else {
1093
- this.rules = inline$1.gfm;
1094
- }
1095
- }
1096
- }
1097
- /**
1098
- * Expose Inline Rules
1099
- */
1100
-
1101
-
1102
- /**
1103
- * Static Lexing/Compiling Method
1104
- */
1105
- InlineLexer.output = function output(src, links, options) {
1106
- var inline = new InlineLexer(links, options);
1107
- return inline.output(src);
1108
- }
1109
- /**
1110
- * Lexing/Compiling
1111
- */
1112
- ;
1113
-
1114
- var _proto = InlineLexer.prototype;
1115
-
1116
- _proto.output = function output(src) {
1117
- var out = '',
1118
- link,
1119
- text,
1120
- href,
1121
- title,
1122
- cap,
1123
- prevCapZero;
1124
-
1125
- while (src) {
1126
- // escape
1127
- if (cap = this.rules.escape.exec(src)) {
1128
- src = src.substring(cap[0].length);
1129
- out += escape$3(cap[1]);
1130
- continue;
1131
- } // tag
1132
-
1133
-
1134
- if (cap = this.rules.tag.exec(src)) {
1135
- if (!this.inLink && /^<a /i.test(cap[0])) {
1136
- this.inLink = true;
1137
- } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
1138
- this.inLink = false;
1139
- }
1140
-
1141
- if (!this.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
1142
- this.inRawBlock = true;
1143
- } else if (this.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
1144
- this.inRawBlock = false;
1145
- }
1146
-
1147
- src = src.substring(cap[0].length);
1148
- out += this.renderer.html(this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$3(cap[0]) : cap[0]);
1149
- continue;
1150
- } // link
1151
-
1152
-
1153
- if (cap = this.rules.link.exec(src)) {
1154
- var lastParenIndex = findClosingBracket$1(cap[2], '()');
1155
-
1156
- if (lastParenIndex > -1) {
1157
- var start = cap[0].indexOf('!') === 0 ? 5 : 4;
1158
- var linkLen = start + cap[1].length + lastParenIndex;
1159
- cap[2] = cap[2].substring(0, lastParenIndex);
1160
- cap[0] = cap[0].substring(0, linkLen).trim();
1161
- cap[3] = '';
1162
- }
1163
-
1164
- src = src.substring(cap[0].length);
1165
- this.inLink = true;
1166
- href = cap[2];
1167
-
1168
- if (this.options.pedantic) {
1169
- link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
1170
-
1171
- if (link) {
1172
- href = link[1];
1173
- title = link[3];
1174
- } else {
1175
- title = '';
1176
- }
1177
- } else {
1178
- title = cap[3] ? cap[3].slice(1, -1) : '';
1179
- }
1180
-
1181
- href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
1182
- out += this.outputLink(cap, {
1183
- href: InlineLexer.escapes(href),
1184
- title: InlineLexer.escapes(title)
1185
- });
1186
- this.inLink = false;
1187
- continue;
1188
- } // reflink, nolink
1189
-
1190
-
1191
- if ((cap = this.rules.reflink.exec(src)) || (cap = this.rules.nolink.exec(src))) {
1192
- src = src.substring(cap[0].length);
1193
- link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
1194
- link = this.links[link.toLowerCase()];
1195
-
1196
- if (!link || !link.href) {
1197
- out += cap[0].charAt(0);
1198
- src = cap[0].substring(1) + src;
1199
- continue;
1200
- }
1201
-
1202
- this.inLink = true;
1203
- out += this.outputLink(cap, link);
1204
- this.inLink = false;
1205
- continue;
1206
- } // strong
1207
-
1208
-
1209
- if (cap = this.rules.strong.exec(src)) {
1210
- src = src.substring(cap[0].length);
1211
- out += this.renderer.strong(this.output(cap[4] || cap[3] || cap[2] || cap[1]));
1212
- continue;
1213
- } // em
1214
-
1215
-
1216
- if (cap = this.rules.em.exec(src)) {
1217
- src = src.substring(cap[0].length);
1218
- out += this.renderer.em(this.output(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]));
1219
- continue;
1220
- } // code
1221
-
1222
-
1223
- if (cap = this.rules.code.exec(src)) {
1224
- src = src.substring(cap[0].length);
1225
- out += this.renderer.codespan(escape$3(cap[2].trim(), true));
1226
- continue;
1227
- } // br
1228
-
1229
-
1230
- if (cap = this.rules.br.exec(src)) {
1231
- src = src.substring(cap[0].length);
1232
- out += this.renderer.br();
1233
- continue;
1234
- } // del (gfm)
1235
-
1642
+ var type = ordered ? 'ol' : 'ul',
1643
+ startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
1644
+ return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
1645
+ };
1236
1646
 
1237
- if (cap = this.rules.del.exec(src)) {
1238
- src = src.substring(cap[0].length);
1239
- out += this.renderer.del(this.output(cap[1]));
1240
- continue;
1241
- } // autolink
1647
+ _proto.listitem = function listitem(text) {
1648
+ return '<li>' + text + '</li>\n';
1649
+ };
1242
1650
 
1651
+ _proto.checkbox = function checkbox(checked) {
1652
+ return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
1653
+ };
1243
1654
 
1244
- if (cap = this.rules.autolink.exec(src)) {
1245
- src = src.substring(cap[0].length);
1655
+ _proto.paragraph = function paragraph(text) {
1656
+ return '<p>' + text + '</p>\n';
1657
+ };
1246
1658
 
1247
- if (cap[2] === '@') {
1248
- text = escape$3(this.mangle(cap[1]));
1249
- href = 'mailto:' + text;
1250
- } else {
1251
- text = escape$3(cap[1]);
1252
- href = text;
1253
- }
1659
+ _proto.table = function table(header, body) {
1660
+ if (body) body = '<tbody>' + body + '</tbody>';
1661
+ return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
1662
+ };
1254
1663
 
1255
- out += this.renderer.link(href, null, text);
1256
- continue;
1257
- } // url (gfm)
1664
+ _proto.tablerow = function tablerow(content) {
1665
+ return '<tr>\n' + content + '</tr>\n';
1666
+ };
1258
1667
 
1668
+ _proto.tablecell = function tablecell(content, flags) {
1669
+ var type = flags.header ? 'th' : 'td';
1670
+ var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>';
1671
+ return tag + content + '</' + type + '>\n';
1672
+ } // span level renderer
1673
+ ;
1259
1674
 
1260
- if (!this.inLink && (cap = this.rules.url.exec(src))) {
1261
- if (cap[2] === '@') {
1262
- text = escape$3(cap[0]);
1263
- href = 'mailto:' + text;
1264
- } else {
1265
- // do extended autolink path validation
1266
- do {
1267
- prevCapZero = cap[0];
1268
- cap[0] = this.rules._backpedal.exec(cap[0])[0];
1269
- } while (prevCapZero !== cap[0]);
1675
+ _proto.strong = function strong(text) {
1676
+ return '<strong>' + text + '</strong>';
1677
+ };
1270
1678
 
1271
- text = escape$3(cap[0]);
1679
+ _proto.em = function em(text) {
1680
+ return '<em>' + text + '</em>';
1681
+ };
1272
1682
 
1273
- if (cap[1] === 'www.') {
1274
- href = 'http://' + text;
1275
- } else {
1276
- href = text;
1277
- }
1278
- }
1683
+ _proto.codespan = function codespan(text) {
1684
+ return '<code>' + text + '</code>';
1685
+ };
1279
1686
 
1280
- src = src.substring(cap[0].length);
1281
- out += this.renderer.link(href, null, text);
1282
- continue;
1283
- } // text
1687
+ _proto.br = function br() {
1688
+ return this.options.xhtml ? '<br/>' : '<br>';
1689
+ };
1284
1690
 
1691
+ _proto.del = function del(text) {
1692
+ return '<del>' + text + '</del>';
1693
+ };
1285
1694
 
1286
- if (cap = this.rules.text.exec(src)) {
1287
- src = src.substring(cap[0].length);
1695
+ _proto.link = function link(href, title, text) {
1696
+ href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
1288
1697
 
1289
- if (this.inRawBlock) {
1290
- out += this.renderer.text(this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$3(cap[0]) : cap[0]);
1291
- } else {
1292
- out += this.renderer.text(escape$3(this.smartypants(cap[0])));
1293
- }
1698
+ if (href === null) {
1699
+ return text;
1700
+ }
1294
1701
 
1295
- continue;
1296
- }
1702
+ var out = '<a href="' + escape$1(href) + '"';
1297
1703
 
1298
- if (src) {
1299
- throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
1300
- }
1704
+ if (title) {
1705
+ out += ' title="' + title + '"';
1301
1706
  }
1302
1707
 
1708
+ out += '>' + text + '</a>';
1303
1709
  return out;
1304
1710
  };
1305
1711
 
1306
- InlineLexer.escapes = function escapes(text) {
1307
- return text ? text.replace(InlineLexer.rules._escapes, '$1') : text;
1308
- }
1309
- /**
1310
- * Compile Link
1311
- */
1312
- ;
1313
-
1314
- _proto.outputLink = function outputLink(cap, link) {
1315
- var href = link.href,
1316
- title = link.title ? escape$3(link.title) : null;
1317
- return cap[0].charAt(0) !== '!' ? this.renderer.link(href, title, this.output(cap[1])) : this.renderer.image(href, title, escape$3(cap[1]));
1318
- }
1319
- /**
1320
- * Smartypants Transformations
1321
- */
1322
- ;
1323
-
1324
- _proto.smartypants = function smartypants(text) {
1325
- if (!this.options.smartypants) return text;
1326
- return text // em-dashes
1327
- .replace(/---/g, "\u2014") // en-dashes
1328
- .replace(/--/g, "\u2013") // opening singles
1329
- .replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // closing singles & apostrophes
1330
- .replace(/'/g, "\u2019") // opening doubles
1331
- .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C") // closing doubles
1332
- .replace(/"/g, "\u201D") // ellipses
1333
- .replace(/\.{3}/g, "\u2026");
1334
- }
1335
- /**
1336
- * Mangle Links
1337
- */
1338
- ;
1339
-
1340
- _proto.mangle = function mangle(text) {
1341
- if (!this.options.mangle) return text;
1342
- var l = text.length;
1343
- var out = '',
1344
- i = 0,
1345
- ch;
1712
+ _proto.image = function image(href, title, text) {
1713
+ href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
1346
1714
 
1347
- for (; i < l; i++) {
1348
- ch = text.charCodeAt(i);
1715
+ if (href === null) {
1716
+ return text;
1717
+ }
1349
1718
 
1350
- if (Math.random() > 0.5) {
1351
- ch = 'x' + ch.toString(16);
1352
- }
1719
+ var out = '<img src="' + href + '" alt="' + text + '"';
1353
1720
 
1354
- out += '&#' + ch + ';';
1721
+ if (title) {
1722
+ out += ' title="' + title + '"';
1355
1723
  }
1356
1724
 
1725
+ out += this.options.xhtml ? '/>' : '>';
1357
1726
  return out;
1358
1727
  };
1359
1728
 
1360
- _createClass(InlineLexer, null, [{
1361
- key: "rules",
1362
- get: function get() {
1363
- return inline$1;
1364
- }
1365
- }]);
1729
+ _proto.text = function text(_text) {
1730
+ return _text;
1731
+ };
1366
1732
 
1367
- return InlineLexer;
1733
+ return Renderer;
1368
1734
  }();
1369
1735
 
1370
1736
  /**
@@ -1416,21 +1782,54 @@
1416
1782
  return TextRenderer;
1417
1783
  }();
1418
1784
 
1785
+ /**
1786
+ * Slugger generates header id
1787
+ */
1788
+ var Slugger_1 = /*#__PURE__*/function () {
1789
+ function Slugger() {
1790
+ this.seen = {};
1791
+ }
1792
+ /**
1793
+ * Convert string to unique id
1794
+ */
1795
+
1796
+
1797
+ var _proto = Slugger.prototype;
1798
+
1799
+ _proto.slug = function slug(value) {
1800
+ var slug = value.toLowerCase().trim() // remove html tags
1801
+ .replace(/<[!\/a-z].*?>/ig, '') // remove unwanted chars
1802
+ .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
1803
+
1804
+ if (this.seen.hasOwnProperty(slug)) {
1805
+ var originalSlug = slug;
1806
+
1807
+ do {
1808
+ this.seen[originalSlug]++;
1809
+ slug = originalSlug + '-' + this.seen[originalSlug];
1810
+ } while (this.seen.hasOwnProperty(slug));
1811
+ }
1812
+
1813
+ this.seen[slug] = 0;
1814
+ return slug;
1815
+ };
1816
+
1817
+ return Slugger;
1818
+ }();
1819
+
1419
1820
  var defaults$4 = defaults.defaults;
1420
- var merge$2 = helpers.merge,
1421
- unescape$1 = helpers.unescape;
1821
+ var unescape$1 = helpers.unescape;
1422
1822
  /**
1423
1823
  * Parsing & Compiling
1424
1824
  */
1425
1825
 
1426
1826
  var Parser_1 = /*#__PURE__*/function () {
1427
1827
  function Parser(options) {
1428
- this.tokens = [];
1429
- this.token = null;
1430
1828
  this.options = options || defaults$4;
1431
1829
  this.options.renderer = this.options.renderer || new Renderer_1();
1432
1830
  this.renderer = this.options.renderer;
1433
1831
  this.renderer.options = this.options;
1832
+ this.textRenderer = new TextRenderer_1();
1434
1833
  this.slugger = new Slugger_1();
1435
1834
  }
1436
1835
  /**
@@ -1441,209 +1840,295 @@
1441
1840
  Parser.parse = function parse(tokens, options) {
1442
1841
  var parser = new Parser(options);
1443
1842
  return parser.parse(tokens);
1444
- };
1445
-
1446
- var _proto = Parser.prototype;
1447
-
1843
+ }
1448
1844
  /**
1449
1845
  * Parse Loop
1450
1846
  */
1451
- _proto.parse = function parse(tokens) {
1452
- this.inline = new InlineLexer_1(tokens.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text
1847
+ ;
1453
1848
 
1454
- this.inlineText = new InlineLexer_1(tokens.links, merge$2({}, this.options, {
1455
- renderer: new TextRenderer_1()
1456
- }));
1457
- this.tokens = tokens.reverse();
1458
- var out = '';
1849
+ var _proto = Parser.prototype;
1459
1850
 
1460
- while (this.next()) {
1461
- out += this.tok();
1851
+ _proto.parse = function parse(tokens, top) {
1852
+ if (top === void 0) {
1853
+ top = true;
1462
1854
  }
1463
1855
 
1464
- return out;
1465
- };
1856
+ var out = '',
1857
+ i,
1858
+ j,
1859
+ k,
1860
+ l2,
1861
+ l3,
1862
+ row,
1863
+ cell,
1864
+ header,
1865
+ body,
1866
+ token,
1867
+ ordered,
1868
+ start,
1869
+ loose,
1870
+ itemBody,
1871
+ item,
1872
+ checked,
1873
+ task,
1874
+ checkbox;
1875
+ var l = tokens.length;
1876
+
1877
+ for (i = 0; i < l; i++) {
1878
+ token = tokens[i];
1879
+
1880
+ switch (token.type) {
1881
+ case 'space':
1882
+ {
1883
+ continue;
1884
+ }
1466
1885
 
1467
- /**
1468
- * Next Token
1469
- */
1470
- _proto.next = function next() {
1471
- this.token = this.tokens.pop();
1472
- return this.token;
1473
- };
1886
+ case 'hr':
1887
+ {
1888
+ out += this.renderer.hr();
1889
+ continue;
1890
+ }
1474
1891
 
1475
- /**
1476
- * Preview Next Token
1477
- */
1478
- _proto.peek = function peek() {
1479
- return this.tokens[this.tokens.length - 1] || 0;
1480
- };
1892
+ case 'heading':
1893
+ {
1894
+ out += this.renderer.heading(this.parseInline(token.tokens), token.depth, unescape$1(this.parseInline(token.tokens, this.textRenderer)), this.slugger);
1895
+ continue;
1896
+ }
1481
1897
 
1482
- /**
1483
- * Parse Text Tokens
1484
- */
1485
- _proto.parseText = function parseText() {
1486
- var body = this.token.text;
1898
+ case 'code':
1899
+ {
1900
+ out += this.renderer.code(token.text, token.lang, token.escaped);
1901
+ continue;
1902
+ }
1487
1903
 
1488
- while (this.peek().type === 'text') {
1489
- body += '\n' + this.next().text;
1490
- }
1904
+ case 'table':
1905
+ {
1906
+ header = ''; // header
1491
1907
 
1492
- return this.inline.output(body);
1493
- };
1908
+ cell = '';
1909
+ l2 = token.header.length;
1494
1910
 
1495
- /**
1496
- * Parse Current Token
1497
- */
1498
- _proto.tok = function tok() {
1499
- var body = '';
1911
+ for (j = 0; j < l2; j++) {
1912
+ cell += this.renderer.tablecell(this.parseInline(token.tokens.header[j]), {
1913
+ header: true,
1914
+ align: token.align[j]
1915
+ });
1916
+ }
1500
1917
 
1501
- switch (this.token.type) {
1502
- case 'space':
1503
- {
1504
- return '';
1505
- }
1918
+ header += this.renderer.tablerow(cell);
1919
+ body = '';
1920
+ l2 = token.cells.length;
1506
1921
 
1507
- case 'hr':
1508
- {
1509
- return this.renderer.hr();
1510
- }
1922
+ for (j = 0; j < l2; j++) {
1923
+ row = token.tokens.cells[j];
1924
+ cell = '';
1925
+ l3 = row.length;
1511
1926
 
1512
- case 'heading':
1513
- {
1514
- return this.renderer.heading(this.inline.output(this.token.text), this.token.depth, unescape$1(this.inlineText.output(this.token.text)), this.slugger);
1515
- }
1927
+ for (k = 0; k < l3; k++) {
1928
+ cell += this.renderer.tablecell(this.parseInline(row[k]), {
1929
+ header: false,
1930
+ align: token.align[k]
1931
+ });
1932
+ }
1516
1933
 
1517
- case 'code':
1518
- {
1519
- return this.renderer.code(this.token.text, this.token.lang, this.token.escaped);
1520
- }
1934
+ body += this.renderer.tablerow(cell);
1935
+ }
1521
1936
 
1522
- case 'table':
1523
- {
1524
- var header = '',
1525
- i,
1526
- row,
1527
- cell,
1528
- j; // header
1529
-
1530
- cell = '';
1531
-
1532
- for (i = 0; i < this.token.header.length; i++) {
1533
- cell += this.renderer.tablecell(this.inline.output(this.token.header[i]), {
1534
- header: true,
1535
- align: this.token.align[i]
1536
- });
1937
+ out += this.renderer.table(header, body);
1938
+ continue;
1537
1939
  }
1538
1940
 
1539
- header += this.renderer.tablerow(cell);
1941
+ case 'blockquote':
1942
+ {
1943
+ body = this.parse(token.tokens);
1944
+ out += this.renderer.blockquote(body);
1945
+ continue;
1946
+ }
1540
1947
 
1541
- for (i = 0; i < this.token.cells.length; i++) {
1542
- row = this.token.cells[i];
1543
- cell = '';
1948
+ case 'list':
1949
+ {
1950
+ ordered = token.ordered;
1951
+ start = token.start;
1952
+ loose = token.loose;
1953
+ l2 = token.items.length;
1954
+ body = '';
1955
+
1956
+ for (j = 0; j < l2; j++) {
1957
+ item = token.items[j];
1958
+ checked = item.checked;
1959
+ task = item.task;
1960
+ itemBody = '';
1961
+
1962
+ if (item.task) {
1963
+ checkbox = this.renderer.checkbox(checked);
1964
+
1965
+ if (loose) {
1966
+ if (item.tokens[0].type === 'text') {
1967
+ item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
1968
+
1969
+ if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
1970
+ item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
1971
+ }
1972
+ } else {
1973
+ item.tokens.unshift({
1974
+ type: 'text',
1975
+ text: checkbox
1976
+ });
1977
+ }
1978
+ } else {
1979
+ itemBody += checkbox;
1980
+ }
1981
+ }
1544
1982
 
1545
- for (j = 0; j < row.length; j++) {
1546
- cell += this.renderer.tablecell(this.inline.output(row[j]), {
1547
- header: false,
1548
- align: this.token.align[j]
1549
- });
1983
+ itemBody += this.parse(item.tokens, loose);
1984
+ body += this.renderer.listitem(itemBody, task, checked);
1550
1985
  }
1551
1986
 
1552
- body += this.renderer.tablerow(cell);
1987
+ out += this.renderer.list(body, ordered, start);
1988
+ continue;
1553
1989
  }
1554
1990
 
1555
- return this.renderer.table(header, body);
1556
- }
1557
-
1558
- case 'blockquote_start':
1559
- {
1560
- body = '';
1991
+ case 'html':
1992
+ {
1993
+ // TODO parse inline content if parameter markdown=1
1994
+ out += this.renderer.html(token.text);
1995
+ continue;
1996
+ }
1561
1997
 
1562
- while (this.next().type !== 'blockquote_end') {
1563
- body += this.tok();
1998
+ case 'paragraph':
1999
+ {
2000
+ out += this.renderer.paragraph(this.parseInline(token.tokens));
2001
+ continue;
1564
2002
  }
1565
2003
 
1566
- return this.renderer.blockquote(body);
1567
- }
2004
+ case 'text':
2005
+ {
2006
+ body = token.tokens ? this.parseInline(token.tokens) : token.text;
1568
2007
 
1569
- case 'list_start':
1570
- {
1571
- body = '';
1572
- var ordered = this.token.ordered,
1573
- start = this.token.start;
2008
+ while (i + 1 < l && tokens[i + 1].type === 'text') {
2009
+ token = tokens[++i];
2010
+ body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
2011
+ }
1574
2012
 
1575
- while (this.next().type !== 'list_end') {
1576
- body += this.tok();
2013
+ out += top ? this.renderer.paragraph(body) : body;
2014
+ continue;
1577
2015
  }
1578
2016
 
1579
- return this.renderer.list(body, ordered, start);
1580
- }
2017
+ default:
2018
+ {
2019
+ var errMsg = 'Token with "' + token.type + '" type was not found.';
1581
2020
 
1582
- case 'list_item_start':
1583
- {
1584
- body = '';
1585
- var loose = this.token.loose;
1586
- var checked = this.token.checked;
1587
- var task = this.token.task;
1588
-
1589
- if (this.token.task) {
1590
- if (loose) {
1591
- if (this.peek().type === 'text') {
1592
- var nextToken = this.peek();
1593
- nextToken.text = this.renderer.checkbox(checked) + ' ' + nextToken.text;
1594
- } else {
1595
- this.tokens.push({
1596
- type: 'text',
1597
- text: this.renderer.checkbox(checked)
1598
- });
1599
- }
2021
+ if (this.options.silent) {
2022
+ console.error(errMsg);
2023
+ return;
1600
2024
  } else {
1601
- body += this.renderer.checkbox(checked);
2025
+ throw new Error(errMsg);
1602
2026
  }
1603
2027
  }
2028
+ }
2029
+ }
2030
+
2031
+ return out;
2032
+ }
2033
+ /**
2034
+ * Parse Inline Tokens
2035
+ */
2036
+ ;
2037
+
2038
+ _proto.parseInline = function parseInline(tokens, renderer) {
2039
+ renderer = renderer || this.renderer;
2040
+ var out = '',
2041
+ i,
2042
+ token;
2043
+ var l = tokens.length;
2044
+
2045
+ for (i = 0; i < l; i++) {
2046
+ token = tokens[i];
2047
+
2048
+ switch (token.type) {
2049
+ case 'escape':
2050
+ {
2051
+ out += renderer.text(token.text);
2052
+ break;
2053
+ }
1604
2054
 
1605
- while (this.next().type !== 'list_item_end') {
1606
- body += !loose && this.token.type === 'text' ? this.parseText() : this.tok();
2055
+ case 'html':
2056
+ {
2057
+ out += renderer.html(token.text);
2058
+ break;
1607
2059
  }
1608
2060
 
1609
- return this.renderer.listitem(body, task, checked);
1610
- }
2061
+ case 'link':
2062
+ {
2063
+ out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
2064
+ break;
2065
+ }
1611
2066
 
1612
- case 'html':
1613
- {
1614
- // TODO parse inline content if parameter markdown=1
1615
- return this.renderer.html(this.token.text);
1616
- }
2067
+ case 'image':
2068
+ {
2069
+ out += renderer.image(token.href, token.title, token.text);
2070
+ break;
2071
+ }
1617
2072
 
1618
- case 'paragraph':
1619
- {
1620
- return this.renderer.paragraph(this.inline.output(this.token.text));
1621
- }
2073
+ case 'strong':
2074
+ {
2075
+ out += renderer.strong(this.parseInline(token.tokens, renderer));
2076
+ break;
2077
+ }
1622
2078
 
1623
- case 'text':
1624
- {
1625
- return this.renderer.paragraph(this.parseText());
1626
- }
2079
+ case 'em':
2080
+ {
2081
+ out += renderer.em(this.parseInline(token.tokens, renderer));
2082
+ break;
2083
+ }
1627
2084
 
1628
- default:
1629
- {
1630
- var errMsg = 'Token with "' + this.token.type + '" type was not found.';
2085
+ case 'codespan':
2086
+ {
2087
+ out += renderer.codespan(token.text);
2088
+ break;
2089
+ }
1631
2090
 
1632
- if (this.options.silent) {
1633
- console.log(errMsg);
1634
- } else {
1635
- throw new Error(errMsg);
2091
+ case 'br':
2092
+ {
2093
+ out += renderer.br();
2094
+ break;
1636
2095
  }
1637
- }
2096
+
2097
+ case 'del':
2098
+ {
2099
+ out += renderer.del(this.parseInline(token.tokens, renderer));
2100
+ break;
2101
+ }
2102
+
2103
+ case 'text':
2104
+ {
2105
+ out += renderer.text(token.text);
2106
+ break;
2107
+ }
2108
+
2109
+ default:
2110
+ {
2111
+ var errMsg = 'Token with "' + token.type + '" type was not found.';
2112
+
2113
+ if (this.options.silent) {
2114
+ console.error(errMsg);
2115
+ return;
2116
+ } else {
2117
+ throw new Error(errMsg);
2118
+ }
2119
+ }
2120
+ }
1638
2121
  }
2122
+
2123
+ return out;
1639
2124
  };
1640
2125
 
1641
2126
  return Parser;
1642
2127
  }();
1643
2128
 
1644
- var merge$3 = helpers.merge,
2129
+ var merge$2 = helpers.merge,
1645
2130
  checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation,
1646
- escape$4 = helpers.escape;
2131
+ escape$2 = helpers.escape;
1647
2132
  var getDefaults = defaults.getDefaults,
1648
2133
  changeDefaults = defaults.changeDefaults,
1649
2134
  defaults$5 = defaults.defaults;
@@ -1668,7 +2153,7 @@
1668
2153
  opt = null;
1669
2154
  }
1670
2155
 
1671
- opt = merge$3({}, marked.defaults, opt || {});
2156
+ opt = merge$2({}, marked.defaults, opt || {});
1672
2157
  checkSanitizeDeprecation$1(opt);
1673
2158
  var highlight = opt.highlight;
1674
2159
  var tokens,
@@ -1743,14 +2228,14 @@
1743
2228
  }
1744
2229
 
1745
2230
  try {
1746
- opt = merge$3({}, marked.defaults, opt || {});
2231
+ opt = merge$2({}, marked.defaults, opt || {});
1747
2232
  checkSanitizeDeprecation$1(opt);
1748
2233
  return Parser_1.parse(Lexer_1.lex(src, opt), opt);
1749
2234
  } catch (e) {
1750
2235
  e.message += '\nPlease report this to https://github.com/markedjs/marked.';
1751
2236
 
1752
2237
  if ((opt || marked.defaults).silent) {
1753
- return '<p>An error occurred:</p><pre>' + escape$4(e.message + '', true) + '</pre>';
2238
+ return '<p>An error occurred:</p><pre>' + escape$2(e.message + '', true) + '</pre>';
1754
2239
  }
1755
2240
 
1756
2241
  throw e;
@@ -1762,25 +2247,94 @@
1762
2247
 
1763
2248
 
1764
2249
  marked.options = marked.setOptions = function (opt) {
1765
- merge$3(marked.defaults, opt);
2250
+ merge$2(marked.defaults, opt);
1766
2251
  changeDefaults(marked.defaults);
1767
2252
  return marked;
1768
2253
  };
1769
2254
 
1770
2255
  marked.getDefaults = getDefaults;
1771
2256
  marked.defaults = defaults$5;
2257
+ /**
2258
+ * Use Extension
2259
+ */
2260
+
2261
+ marked.use = function (extension) {
2262
+ var opts = merge$2({}, extension);
2263
+
2264
+ if (extension.renderer) {
2265
+ (function () {
2266
+ var renderer = marked.defaults.renderer || new Renderer_1();
2267
+
2268
+ var _loop = function _loop(prop) {
2269
+ var prevRenderer = renderer[prop];
2270
+
2271
+ renderer[prop] = function () {
2272
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2273
+ args[_key] = arguments[_key];
2274
+ }
2275
+
2276
+ var ret = extension.renderer[prop].apply(renderer, args);
2277
+
2278
+ if (ret === false) {
2279
+ ret = prevRenderer.apply(renderer, args);
2280
+ }
2281
+
2282
+ return ret;
2283
+ };
2284
+ };
2285
+
2286
+ for (var prop in extension.renderer) {
2287
+ _loop(prop);
2288
+ }
2289
+
2290
+ opts.renderer = renderer;
2291
+ })();
2292
+ }
2293
+
2294
+ if (extension.tokenizer) {
2295
+ (function () {
2296
+ var tokenizer = marked.defaults.tokenizer || new Tokenizer_1();
2297
+
2298
+ var _loop2 = function _loop2(prop) {
2299
+ var prevTokenizer = tokenizer[prop];
2300
+
2301
+ tokenizer[prop] = function () {
2302
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2303
+ args[_key2] = arguments[_key2];
2304
+ }
2305
+
2306
+ var ret = extension.tokenizer[prop].apply(tokenizer, args);
2307
+
2308
+ if (ret === false) {
2309
+ ret = prevTokenizer.apply(tokenizer, args);
2310
+ }
2311
+
2312
+ return ret;
2313
+ };
2314
+ };
2315
+
2316
+ for (var prop in extension.tokenizer) {
2317
+ _loop2(prop);
2318
+ }
2319
+
2320
+ opts.tokenizer = tokenizer;
2321
+ })();
2322
+ }
2323
+
2324
+ marked.setOptions(opts);
2325
+ };
1772
2326
  /**
1773
2327
  * Expose
1774
2328
  */
1775
2329
 
2330
+
1776
2331
  marked.Parser = Parser_1;
1777
2332
  marked.parser = Parser_1.parse;
1778
2333
  marked.Renderer = Renderer_1;
1779
2334
  marked.TextRenderer = TextRenderer_1;
1780
2335
  marked.Lexer = Lexer_1;
1781
2336
  marked.lexer = Lexer_1.lex;
1782
- marked.InlineLexer = InlineLexer_1;
1783
- marked.inlineLexer = InlineLexer_1.output;
2337
+ marked.Tokenizer = Tokenizer_1;
1784
2338
  marked.Slugger = Slugger_1;
1785
2339
  marked.parse = marked;
1786
2340
  var marked_1 = marked;