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