marked 1.0.0 → 1.2.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
@@ -31,6 +31,48 @@
31
31
  return Constructor;
32
32
  }
33
33
 
34
+ function _unsupportedIterableToArray(o, minLen) {
35
+ if (!o) return;
36
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
37
+ var n = Object.prototype.toString.call(o).slice(8, -1);
38
+ if (n === "Object" && o.constructor) n = o.constructor.name;
39
+ if (n === "Map" || n === "Set") return Array.from(o);
40
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
41
+ }
42
+
43
+ function _arrayLikeToArray(arr, len) {
44
+ if (len == null || len > arr.length) len = arr.length;
45
+
46
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
47
+
48
+ return arr2;
49
+ }
50
+
51
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
52
+ var it;
53
+
54
+ if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
55
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
56
+ if (it) o = it;
57
+ var i = 0;
58
+ return function () {
59
+ if (i >= o.length) return {
60
+ done: true
61
+ };
62
+ return {
63
+ done: false,
64
+ value: o[i++]
65
+ };
66
+ };
67
+ }
68
+
69
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
70
+ }
71
+
72
+ it = o[Symbol.iterator]();
73
+ return it.next.bind(it);
74
+ }
75
+
34
76
  function createCommonjsModule(fn, module) {
35
77
  return module = { exports: {} }, fn(module, module.exports), module.exports;
36
78
  }
@@ -54,6 +96,7 @@
54
96
  smartLists: false,
55
97
  smartypants: false,
56
98
  tokenizer: null,
99
+ walkTokens: null,
57
100
  xhtml: false
58
101
  };
59
102
  }
@@ -352,6 +395,7 @@
352
395
  function outputLink(cap, link, raw) {
353
396
  var href = link.href;
354
397
  var title = link.title ? _escape(link.title) : null;
398
+ var text = cap[1].replace(/\\([\[\]])/g, '$1');
355
399
 
356
400
  if (cap[0].charAt(0) !== '!') {
357
401
  return {
@@ -359,18 +403,43 @@
359
403
  raw: raw,
360
404
  href: href,
361
405
  title: title,
362
- text: cap[1]
406
+ text: text
363
407
  };
364
408
  } else {
365
409
  return {
366
410
  type: 'image',
367
411
  raw: raw,
368
- text: _escape(cap[1]),
369
412
  href: href,
370
- title: title
413
+ title: title,
414
+ text: _escape(text)
371
415
  };
372
416
  }
373
417
  }
418
+
419
+ function indentCodeCompensation(raw, text) {
420
+ var matchIndentToCode = raw.match(/^(\s+)(?:```)/);
421
+
422
+ if (matchIndentToCode === null) {
423
+ return text;
424
+ }
425
+
426
+ var indentToCode = matchIndentToCode[1];
427
+ return text.split('\n').map(function (node) {
428
+ var matchIndentInNode = node.match(/^\s+/);
429
+
430
+ if (matchIndentInNode === null) {
431
+ return node;
432
+ }
433
+
434
+ var indentInNode = matchIndentInNode[0];
435
+
436
+ if (indentInNode.length >= indentToCode.length) {
437
+ return node.slice(indentToCode.length);
438
+ }
439
+
440
+ return node;
441
+ }).join('\n');
442
+ }
374
443
  /**
375
444
  * Tokenizer
376
445
  */
@@ -407,19 +476,19 @@
407
476
  var lastToken = tokens[tokens.length - 1]; // An indented code block cannot interrupt a paragraph.
408
477
 
409
478
  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
479
  return {
417
- type: 'code',
418
480
  raw: cap[0],
419
- codeBlockStyle: 'indented',
420
- text: !this.options.pedantic ? rtrim$1(text, '\n') : text
481
+ text: cap[0].trimRight()
421
482
  };
422
483
  }
484
+
485
+ var text = cap[0].replace(/^ {4}/gm, '');
486
+ return {
487
+ type: 'code',
488
+ raw: cap[0],
489
+ codeBlockStyle: 'indented',
490
+ text: !this.options.pedantic ? rtrim$1(text, '\n') : text
491
+ };
423
492
  }
424
493
  };
425
494
 
@@ -427,11 +496,13 @@
427
496
  var cap = this.rules.block.fences.exec(src);
428
497
 
429
498
  if (cap) {
499
+ var raw = cap[0];
500
+ var text = indentCodeCompensation(raw, cap[3] || '');
430
501
  return {
431
502
  type: 'code',
432
- raw: cap[0],
503
+ raw: raw,
433
504
  lang: cap[2] ? cap[2].trim() : cap[2],
434
- text: cap[3] || ''
505
+ text: text
435
506
  };
436
507
  }
437
508
  };
@@ -519,11 +590,12 @@
519
590
  var raw = cap[0];
520
591
  var bull = cap[2];
521
592
  var isordered = bull.length > 1;
593
+ var isparen = bull[bull.length - 1] === ')';
522
594
  var list = {
523
595
  type: 'list',
524
596
  raw: raw,
525
597
  ordered: isordered,
526
- start: isordered ? +bull : '',
598
+ start: isordered ? +bull.slice(0, -1) : '',
527
599
  loose: false,
528
600
  items: []
529
601
  }; // Get each top-level item.
@@ -545,7 +617,7 @@
545
617
  // so it is seen as the next token.
546
618
 
547
619
  space = item.length;
548
- item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the
620
+ item = item.replace(/^ *([*+-]|\d+[.)]) */, ''); // Outdent whatever the
549
621
  // list item contains. Hacky.
550
622
 
551
623
  if (~item.indexOf('\n ')) {
@@ -558,7 +630,7 @@
558
630
  if (i !== l - 1) {
559
631
  b = this.rules.block.bullet.exec(itemMatch[i + 1])[0];
560
632
 
561
- if (bull.length > 1 ? b.length === 1 : b.length > 1 || this.options.smartLists && b !== bull) {
633
+ if (isordered ? b.length === 1 || !isparen && b[b.length - 1] === ')' : b.length > 1 || this.options.smartLists && b !== bull) {
562
634
  addBack = itemMatch.slice(i + 1).join('\n');
563
635
  list.raw = list.raw.substring(0, list.raw.length - addBack.length);
564
636
  i = l - 1;
@@ -589,6 +661,7 @@
589
661
  }
590
662
 
591
663
  list.items.push({
664
+ type: 'list_item',
592
665
  raw: raw,
593
666
  task: istask,
594
667
  checked: ischecked,
@@ -693,10 +766,19 @@
693
766
  }
694
767
  };
695
768
 
696
- _proto.text = function text(src) {
769
+ _proto.text = function text(src, tokens) {
697
770
  var cap = this.rules.block.text.exec(src);
698
771
 
699
772
  if (cap) {
773
+ var lastToken = tokens[tokens.length - 1];
774
+
775
+ if (lastToken && lastToken.type === 'text') {
776
+ return {
777
+ raw: cap[0],
778
+ text: cap[0]
779
+ };
780
+ }
781
+
700
782
  return {
701
783
  type: 'text',
702
784
  raw: cap[0],
@@ -803,27 +885,57 @@
803
885
  }
804
886
  };
805
887
 
806
- _proto.strong = function strong(src) {
807
- var cap = this.rules.inline.strong.exec(src);
888
+ _proto.strong = function strong(src, maskedSrc, prevChar) {
889
+ if (prevChar === void 0) {
890
+ prevChar = '';
891
+ }
808
892
 
809
- if (cap) {
810
- return {
811
- type: 'strong',
812
- raw: cap[0],
813
- text: cap[4] || cap[3] || cap[2] || cap[1]
814
- };
893
+ var match = this.rules.inline.strong.start.exec(src);
894
+
895
+ if (match && (!match[1] || match[1] && (prevChar === '' || this.rules.inline.punctuation.exec(prevChar)))) {
896
+ maskedSrc = maskedSrc.slice(-1 * src.length);
897
+ var endReg = match[0] === '**' ? this.rules.inline.strong.endAst : this.rules.inline.strong.endUnd;
898
+ endReg.lastIndex = 0;
899
+ var cap;
900
+
901
+ while ((match = endReg.exec(maskedSrc)) != null) {
902
+ cap = this.rules.inline.strong.middle.exec(maskedSrc.slice(0, match.index + 3));
903
+
904
+ if (cap) {
905
+ return {
906
+ type: 'strong',
907
+ raw: src.slice(0, cap[0].length),
908
+ text: src.slice(2, cap[0].length - 2)
909
+ };
910
+ }
911
+ }
815
912
  }
816
913
  };
817
914
 
818
- _proto.em = function em(src) {
819
- var cap = this.rules.inline.em.exec(src);
915
+ _proto.em = function em(src, maskedSrc, prevChar) {
916
+ if (prevChar === void 0) {
917
+ prevChar = '';
918
+ }
820
919
 
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
- };
920
+ var match = this.rules.inline.em.start.exec(src);
921
+
922
+ if (match && (!match[1] || match[1] && (prevChar === '' || this.rules.inline.punctuation.exec(prevChar)))) {
923
+ maskedSrc = maskedSrc.slice(-1 * src.length);
924
+ var endReg = match[0] === '*' ? this.rules.inline.em.endAst : this.rules.inline.em.endUnd;
925
+ endReg.lastIndex = 0;
926
+ var cap;
927
+
928
+ while ((match = endReg.exec(maskedSrc)) != null) {
929
+ cap = this.rules.inline.em.middle.exec(maskedSrc.slice(0, match.index + 2));
930
+
931
+ if (cap) {
932
+ return {
933
+ type: 'em',
934
+ raw: src.slice(0, cap[0].length),
935
+ text: src.slice(1, cap[0].length - 1)
936
+ };
937
+ }
938
+ }
827
939
  }
828
940
  };
829
941
 
@@ -831,10 +943,19 @@
831
943
  var cap = this.rules.inline.code.exec(src);
832
944
 
833
945
  if (cap) {
946
+ var text = cap[2].replace(/\n/g, ' ');
947
+ var hasNonSpaceChars = /[^ ]/.test(text);
948
+ var hasSpaceCharsOnBothEnds = text.startsWith(' ') && text.endsWith(' ');
949
+
950
+ if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
951
+ text = text.substring(1, text.length - 1);
952
+ }
953
+
954
+ text = _escape(text, true);
834
955
  return {
835
956
  type: 'codespan',
836
957
  raw: cap[0],
837
- text: _escape(cap[2].trim(), true)
958
+ text: text
838
959
  };
839
960
  }
840
961
  };
@@ -972,9 +1093,9 @@
972
1093
  html: '^ {0,3}(?:' // optional indentation
973
1094
  + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
974
1095
  + '|comment[^\\n]*(\\n+|$)' // (2)
975
- + '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
976
- + '|<![A-Z][\\s\\S]*?>\\n*' // (4)
977
- + '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5)
1096
+ + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
1097
+ + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
1098
+ + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
978
1099
  + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
979
1100
  + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
980
1101
  + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
@@ -991,12 +1112,12 @@
991
1112
  block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
992
1113
  block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
993
1114
  block.def = edit$1(block.def).replace('label', block._label).replace('title', block._title).getRegex();
994
- block.bullet = /(?:[*+-]|\d{1,9}\.)/;
1115
+ block.bullet = /(?:[*+-]|\d{1,9}[.)])/;
995
1116
  block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
996
1117
  block.item = edit$1(block.item, 'gm').replace(/bull/g, block.bullet).getRegex();
997
1118
  block.list = edit$1(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex();
998
1119
  block._tag = 'address|article|aside|base|basefont|blockquote|body|caption' + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption' + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe' + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option' + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr' + '|track|ul';
999
- block._comment = /<!--(?!-?>)[\s\S]*?-->/;
1120
+ block._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;
1000
1121
  block.html = edit$1(block.html, 'i').replace('comment', block._comment).replace('tag', block._tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
1001
1122
  block.paragraph = edit$1(block._paragraph).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} ').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
1002
1123
  .replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
@@ -1014,11 +1135,11 @@
1014
1135
 
1015
1136
  block.gfm = merge$1({}, block.normal, {
1016
1137
  nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
1017
- + ' *([-:]+ *\\|[-| :]*)' // Align
1138
+ + ' {0,3}([-:]+ *\\|[-| :]*)' // Align
1018
1139
  + '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)',
1019
1140
  // Cells
1020
1141
  table: '^ *\\|(.+)\\n' // Header
1021
- + ' *\\|?( *[-:]+[-| :]*)' // Align
1142
+ + ' {0,3}\\|?( *[-:]+[-| :]*)' // Align
1022
1143
  + '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
1023
1144
 
1024
1145
  });
@@ -1058,28 +1179,61 @@
1058
1179
  link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
1059
1180
  reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
1060
1181
  nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
1061
- strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\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])\*(?!\*)/,
1182
+ reflinkSearch: 'reflink|nolink(?!\\()',
1183
+ strong: {
1184
+ start: /^(?:(\*\*(?=[*punctuation]))|\*\*)(?![\s])|__/,
1185
+ // (1) returns if starts w/ punctuation
1186
+ middle: /^\*\*(?:(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)|\*(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)*?\*)+?\*\*$|^__(?![\s])((?:(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)|_(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)*?_)+?)__$/,
1187
+ endAst: /[^punctuation\s]\*\*(?!\*)|[punctuation]\*\*(?!\*)(?:(?=[punctuation_\s]|$))/,
1188
+ // last char can't be punct, or final * must also be followed by punct (or endline)
1189
+ endUnd: /[^\s]__(?!_)(?:(?=[punctuation*\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
1190
+
1191
+ },
1192
+ em: {
1193
+ start: /^(?:(\*(?=[punctuation]))|\*)(?![*\s])|_/,
1194
+ // (1) returns if starts w/ punctuation
1195
+ middle: /^\*(?:(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)|\*(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)*?\*)+?\*$|^_(?![_\s])(?:(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)|_(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)*?_)+?_$/,
1196
+ endAst: /[^punctuation\s]\*(?!\*)|[punctuation]\*(?!\*)(?:(?=[punctuation_\s]|$))/,
1197
+ // last char can't be punct, or final * must also be followed by punct (or endline)
1198
+ endUnd: /[^\s]_(?!_)(?:(?=[punctuation*\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
1199
+
1200
+ },
1063
1201
  code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
1064
1202
  br: /^( {2,}|\\)\n(?!\s*$)/,
1065
1203
  del: noopTest$1,
1066
- text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/
1204
+ text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n)))/,
1205
+ punctuation: /^([\s*punctuation])/
1067
1206
  }; // list of punctuation marks from common mark spec
1068
- // without ` and ] to workaround Rule 17 (inline code blocks/links)
1069
-
1070
- inline._punctuation = '!"#$%&\'()*+\\-./:;<=>?@\\[^_{|}~';
1071
- inline.em = edit$1(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
1207
+ // without * and _ to workaround cases with double emphasis
1208
+
1209
+ inline._punctuation = '!"#$%&\'()+\\-.,/:;<=>?@\\[\\]`^{|}~';
1210
+ inline.punctuation = edit$1(inline.punctuation).replace(/punctuation/g, inline._punctuation).getRegex(); // sequences em should skip over [title](link), `code`, <html>
1211
+
1212
+ inline._blockSkip = '\\[[^\\]]*?\\]\\([^\\)]*?\\)|`[^`]*?`|<[^>]*?>';
1213
+ inline._overlapSkip = '__[^_]*?__|\\*\\*\\[^\\*\\]*?\\*\\*';
1214
+ inline._comment = edit$1(block._comment).replace('(?:-->|$)', '-->').getRegex();
1215
+ inline.em.start = edit$1(inline.em.start).replace(/punctuation/g, inline._punctuation).getRegex();
1216
+ inline.em.middle = edit$1(inline.em.middle).replace(/punctuation/g, inline._punctuation).replace(/overlapSkip/g, inline._overlapSkip).getRegex();
1217
+ inline.em.endAst = edit$1(inline.em.endAst, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
1218
+ inline.em.endUnd = edit$1(inline.em.endUnd, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
1219
+ inline.strong.start = edit$1(inline.strong.start).replace(/punctuation/g, inline._punctuation).getRegex();
1220
+ inline.strong.middle = edit$1(inline.strong.middle).replace(/punctuation/g, inline._punctuation).replace(/overlapSkip/g, inline._overlapSkip).getRegex();
1221
+ inline.strong.endAst = edit$1(inline.strong.endAst, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
1222
+ inline.strong.endUnd = edit$1(inline.strong.endUnd, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
1223
+ inline.blockSkip = edit$1(inline._blockSkip, 'g').getRegex();
1224
+ inline.overlapSkip = edit$1(inline._overlapSkip, 'g').getRegex();
1072
1225
  inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
1073
1226
  inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
1074
1227
  inline._email = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;
1075
1228
  inline.autolink = edit$1(inline.autolink).replace('scheme', inline._scheme).replace('email', inline._email).getRegex();
1076
1229
  inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
1077
- inline.tag = edit$1(inline.tag).replace('comment', block._comment).replace('attribute', inline._attribute).getRegex();
1078
- inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
1230
+ inline.tag = edit$1(inline.tag).replace('comment', inline._comment).replace('attribute', inline._attribute).getRegex();
1231
+ inline._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
1079
1232
  inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
1080
1233
  inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
1081
1234
  inline.link = edit$1(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex();
1082
1235
  inline.reflink = edit$1(inline.reflink).replace('label', inline._label).getRegex();
1236
+ inline.reflinkSearch = edit$1(inline.reflinkSearch, 'g').replace('reflink', inline.reflink).replace('nolink', inline.nolink).getRegex();
1083
1237
  /**
1084
1238
  * Normal Inline Grammar
1085
1239
  */
@@ -1090,8 +1244,18 @@
1090
1244
  */
1091
1245
 
1092
1246
  inline.pedantic = merge$1({}, inline.normal, {
1093
- strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
1094
- em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
1247
+ strong: {
1248
+ start: /^__|\*\*/,
1249
+ middle: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
1250
+ endAst: /\*\*(?!\*)/g,
1251
+ endUnd: /__(?!_)/g
1252
+ },
1253
+ em: {
1254
+ start: /^_|\*/,
1255
+ middle: /^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,
1256
+ endAst: /\*(?!\*)/g,
1257
+ endUnd: /_(?!_)/g
1258
+ },
1095
1259
  link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(),
1096
1260
  reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex()
1097
1261
  });
@@ -1105,7 +1269,7 @@
1105
1269
  url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
1106
1270
  _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
1107
1271
  del: /^~+(?=\S)([\s\S]*?\S)~+/,
1108
- text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
1272
+ text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
1109
1273
  });
1110
1274
  inline.gfm.url = edit$1(inline.gfm.url, 'i').replace('email', inline.gfm._extended_email).getRegex();
1111
1275
  /**
@@ -1206,6 +1370,15 @@
1206
1370
  var lexer = new Lexer(options);
1207
1371
  return lexer.lex(src);
1208
1372
  }
1373
+ /**
1374
+ * Static Lex Inline Method
1375
+ */
1376
+ ;
1377
+
1378
+ Lexer.lexInline = function lexInline(src, options) {
1379
+ var lexer = new Lexer(options);
1380
+ return lexer.inlineTokens(src);
1381
+ }
1209
1382
  /**
1210
1383
  * Preprocessing
1211
1384
  */
@@ -1234,7 +1407,7 @@
1234
1407
  }
1235
1408
 
1236
1409
  src = src.replace(/^ +$/gm, '');
1237
- var token, i, l;
1410
+ var token, i, l, lastToken;
1238
1411
 
1239
1412
  while (src) {
1240
1413
  // newline
@@ -1251,7 +1424,15 @@
1251
1424
 
1252
1425
  if (token = this.tokenizer.code(src, tokens)) {
1253
1426
  src = src.substring(token.raw.length);
1254
- tokens.push(token);
1427
+
1428
+ if (token.type) {
1429
+ tokens.push(token);
1430
+ } else {
1431
+ lastToken = tokens[tokens.length - 1];
1432
+ lastToken.raw += '\n' + token.raw;
1433
+ lastToken.text += '\n' + token.text;
1434
+ }
1435
+
1255
1436
  continue;
1256
1437
  } // fences
1257
1438
 
@@ -1347,9 +1528,17 @@
1347
1528
  } // text
1348
1529
 
1349
1530
 
1350
- if (token = this.tokenizer.text(src)) {
1531
+ if (token = this.tokenizer.text(src, tokens)) {
1351
1532
  src = src.substring(token.raw.length);
1352
- tokens.push(token);
1533
+
1534
+ if (token.type) {
1535
+ tokens.push(token);
1536
+ } else {
1537
+ lastToken = tokens[tokens.length - 1];
1538
+ lastToken.raw += '\n' + token.raw;
1539
+ lastToken.text += '\n' + token.text;
1540
+ }
1541
+
1353
1542
  continue;
1354
1543
  }
1355
1544
 
@@ -1441,7 +1630,7 @@
1441
1630
  */
1442
1631
  ;
1443
1632
 
1444
- _proto.inlineTokens = function inlineTokens(src, tokens, inLink, inRawBlock) {
1633
+ _proto.inlineTokens = function inlineTokens(src, tokens, inLink, inRawBlock, prevChar) {
1445
1634
  if (tokens === void 0) {
1446
1635
  tokens = [];
1447
1636
  }
@@ -1454,7 +1643,31 @@
1454
1643
  inRawBlock = false;
1455
1644
  }
1456
1645
 
1457
- var token;
1646
+ if (prevChar === void 0) {
1647
+ prevChar = '';
1648
+ }
1649
+
1650
+ var token; // String with links masked to avoid interference with em and strong
1651
+
1652
+ var maskedSrc = src;
1653
+ var match; // Mask out reflinks
1654
+
1655
+ if (this.tokens.links) {
1656
+ var links = Object.keys(this.tokens.links);
1657
+
1658
+ if (links.length > 0) {
1659
+ while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
1660
+ if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
1661
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
1662
+ }
1663
+ }
1664
+ }
1665
+ } // Mask out other blocks
1666
+
1667
+
1668
+ while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
1669
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1670
+ }
1458
1671
 
1459
1672
  while (src) {
1460
1673
  // escape
@@ -1498,7 +1711,7 @@
1498
1711
  } // strong
1499
1712
 
1500
1713
 
1501
- if (token = this.tokenizer.strong(src)) {
1714
+ if (token = this.tokenizer.strong(src, maskedSrc, prevChar)) {
1502
1715
  src = src.substring(token.raw.length);
1503
1716
  token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1504
1717
  tokens.push(token);
@@ -1506,7 +1719,7 @@
1506
1719
  } // em
1507
1720
 
1508
1721
 
1509
- if (token = this.tokenizer.em(src)) {
1722
+ if (token = this.tokenizer.em(src, maskedSrc, prevChar)) {
1510
1723
  src = src.substring(token.raw.length);
1511
1724
  token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1512
1725
  tokens.push(token);
@@ -1552,6 +1765,7 @@
1552
1765
 
1553
1766
  if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) {
1554
1767
  src = src.substring(token.raw.length);
1768
+ prevChar = token.raw.slice(-1);
1555
1769
  tokens.push(token);
1556
1770
  continue;
1557
1771
  }
@@ -1611,7 +1825,7 @@
1611
1825
  }
1612
1826
 
1613
1827
  if (!lang) {
1614
- return '<pre><code>' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>';
1828
+ return '<pre><code>' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>\n';
1615
1829
  }
1616
1830
 
1617
1831
  return '<pre><code class="' + this.options.langPrefix + escape$1(lang, true) + '">' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>\n';
@@ -1789,29 +2003,53 @@
1789
2003
  function Slugger() {
1790
2004
  this.seen = {};
1791
2005
  }
1792
- /**
1793
- * Convert string to unique id
1794
- */
1795
-
1796
2006
 
1797
2007
  var _proto = Slugger.prototype;
1798
2008
 
1799
- _proto.slug = function slug(value) {
1800
- var slug = value.toLowerCase().trim() // remove html tags
2009
+ _proto.serialize = function serialize(value) {
2010
+ return value.toLowerCase().trim() // remove html tags
1801
2011
  .replace(/<[!\/a-z].*?>/ig, '') // remove unwanted chars
1802
2012
  .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
2013
+ }
2014
+ /**
2015
+ * Finds the next safe (unique) slug to use
2016
+ */
2017
+ ;
2018
+
2019
+ _proto.getNextSafeSlug = function getNextSafeSlug(originalSlug, isDryRun) {
2020
+ var slug = originalSlug;
2021
+ var occurenceAccumulator = 0;
1803
2022
 
1804
2023
  if (this.seen.hasOwnProperty(slug)) {
1805
- var originalSlug = slug;
2024
+ occurenceAccumulator = this.seen[originalSlug];
1806
2025
 
1807
2026
  do {
1808
- this.seen[originalSlug]++;
1809
- slug = originalSlug + '-' + this.seen[originalSlug];
2027
+ occurenceAccumulator++;
2028
+ slug = originalSlug + '-' + occurenceAccumulator;
1810
2029
  } while (this.seen.hasOwnProperty(slug));
1811
2030
  }
1812
2031
 
1813
- this.seen[slug] = 0;
2032
+ if (!isDryRun) {
2033
+ this.seen[originalSlug] = occurenceAccumulator;
2034
+ this.seen[slug] = 0;
2035
+ }
2036
+
1814
2037
  return slug;
2038
+ }
2039
+ /**
2040
+ * Convert string to unique id
2041
+ * @param {object} options
2042
+ * @param {boolean} options.dryrun Generates the next unique slug without updating the internal accumulator.
2043
+ */
2044
+ ;
2045
+
2046
+ _proto.slug = function slug(value, options) {
2047
+ if (options === void 0) {
2048
+ options = {};
2049
+ }
2050
+
2051
+ var slug = this.serialize(value);
2052
+ return this.getNextSafeSlug(slug, options.dryrun);
1815
2053
  };
1816
2054
 
1817
2055
  return Slugger;
@@ -1841,6 +2079,15 @@
1841
2079
  var parser = new Parser(options);
1842
2080
  return parser.parse(tokens);
1843
2081
  }
2082
+ /**
2083
+ * Static Parse Inline Method
2084
+ */
2085
+ ;
2086
+
2087
+ Parser.parseInline = function parseInline(tokens, options) {
2088
+ var parser = new Parser(options);
2089
+ return parser.parseInline(tokens);
2090
+ }
1844
2091
  /**
1845
2092
  * Parse Loop
1846
2093
  */
@@ -1963,7 +2210,7 @@
1963
2210
  checkbox = this.renderer.checkbox(checked);
1964
2211
 
1965
2212
  if (loose) {
1966
- if (item.tokens[0].type === 'text') {
2213
+ if (item.tokens.length > 0 && item.tokens[0].type === 'text') {
1967
2214
  item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
1968
2215
 
1969
2216
  if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
@@ -2146,95 +2393,89 @@
2146
2393
  throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
2147
2394
  }
2148
2395
 
2149
- if (callback || typeof opt === 'function') {
2150
- var _ret = function () {
2151
- if (!callback) {
2152
- callback = opt;
2153
- opt = null;
2154
- }
2396
+ if (typeof opt === 'function') {
2397
+ callback = opt;
2398
+ opt = null;
2399
+ }
2155
2400
 
2156
- opt = merge$2({}, marked.defaults, opt || {});
2157
- checkSanitizeDeprecation$1(opt);
2158
- var highlight = opt.highlight;
2159
- var tokens,
2160
- pending,
2161
- i = 0;
2401
+ opt = merge$2({}, marked.defaults, opt || {});
2402
+ checkSanitizeDeprecation$1(opt);
2162
2403
 
2163
- try {
2164
- tokens = Lexer_1.lex(src, opt);
2165
- } catch (e) {
2166
- return {
2167
- v: callback(e)
2168
- };
2169
- }
2404
+ if (callback) {
2405
+ var highlight = opt.highlight;
2406
+ var tokens;
2170
2407
 
2171
- pending = tokens.length;
2172
-
2173
- var done = function done(err) {
2174
- if (err) {
2175
- opt.highlight = highlight;
2176
- return callback(err);
2177
- }
2408
+ try {
2409
+ tokens = Lexer_1.lex(src, opt);
2410
+ } catch (e) {
2411
+ return callback(e);
2412
+ }
2178
2413
 
2179
- var out;
2414
+ var done = function done(err) {
2415
+ var out;
2180
2416
 
2417
+ if (!err) {
2181
2418
  try {
2182
2419
  out = Parser_1.parse(tokens, opt);
2183
2420
  } catch (e) {
2184
2421
  err = e;
2185
2422
  }
2186
-
2187
- opt.highlight = highlight;
2188
- return err ? callback(err) : callback(null, out);
2189
- };
2190
-
2191
- if (!highlight || highlight.length < 3) {
2192
- return {
2193
- v: done()
2194
- };
2195
2423
  }
2196
2424
 
2197
- delete opt.highlight;
2198
- if (!pending) return {
2199
- v: done()
2200
- };
2425
+ opt.highlight = highlight;
2426
+ return err ? callback(err) : callback(null, out);
2427
+ };
2201
2428
 
2202
- for (; i < tokens.length; i++) {
2203
- (function (token) {
2204
- if (token.type !== 'code') {
2205
- return --pending || done();
2206
- }
2429
+ if (!highlight || highlight.length < 3) {
2430
+ return done();
2431
+ }
2207
2432
 
2208
- return highlight(token.text, token.lang, function (err, code) {
2209
- if (err) return done(err);
2433
+ delete opt.highlight;
2434
+ if (!tokens.length) return done();
2435
+ var pending = 0;
2436
+ marked.walkTokens(tokens, function (token) {
2437
+ if (token.type === 'code') {
2438
+ pending++;
2439
+ setTimeout(function () {
2440
+ highlight(token.text, token.lang, function (err, code) {
2441
+ if (err) {
2442
+ return done(err);
2443
+ }
2210
2444
 
2211
- if (code == null || code === token.text) {
2212
- return --pending || done();
2445
+ if (code != null && code !== token.text) {
2446
+ token.text = code;
2447
+ token.escaped = true;
2213
2448
  }
2214
2449
 
2215
- token.text = code;
2216
- token.escaped = true;
2217
- --pending || done();
2450
+ pending--;
2451
+
2452
+ if (pending === 0) {
2453
+ done();
2454
+ }
2218
2455
  });
2219
- })(tokens[i]);
2456
+ }, 0);
2220
2457
  }
2458
+ });
2221
2459
 
2222
- return {
2223
- v: void 0
2224
- };
2225
- }();
2460
+ if (pending === 0) {
2461
+ done();
2462
+ }
2226
2463
 
2227
- if (typeof _ret === "object") return _ret.v;
2464
+ return;
2228
2465
  }
2229
2466
 
2230
2467
  try {
2231
- opt = merge$2({}, marked.defaults, opt || {});
2232
- checkSanitizeDeprecation$1(opt);
2233
- return Parser_1.parse(Lexer_1.lex(src, opt), opt);
2468
+ var _tokens = Lexer_1.lex(src, opt);
2469
+
2470
+ if (opt.walkTokens) {
2471
+ marked.walkTokens(_tokens, opt.walkTokens);
2472
+ }
2473
+
2474
+ return Parser_1.parse(_tokens, opt);
2234
2475
  } catch (e) {
2235
2476
  e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2236
2477
 
2237
- if ((opt || marked.defaults).silent) {
2478
+ if (opt.silent) {
2238
2479
  return '<p>An error occurred:</p><pre>' + escape$2(e.message + '', true) + '</pre>';
2239
2480
  }
2240
2481
 
@@ -2321,8 +2562,101 @@
2321
2562
  })();
2322
2563
  }
2323
2564
 
2565
+ if (extension.walkTokens) {
2566
+ var walkTokens = marked.defaults.walkTokens;
2567
+
2568
+ opts.walkTokens = function (token) {
2569
+ extension.walkTokens(token);
2570
+
2571
+ if (walkTokens) {
2572
+ walkTokens(token);
2573
+ }
2574
+ };
2575
+ }
2576
+
2324
2577
  marked.setOptions(opts);
2325
2578
  };
2579
+ /**
2580
+ * Run callback for every token
2581
+ */
2582
+
2583
+
2584
+ marked.walkTokens = function (tokens, callback) {
2585
+ for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
2586
+ var token = _step.value;
2587
+ callback(token);
2588
+
2589
+ switch (token.type) {
2590
+ case 'table':
2591
+ {
2592
+ for (var _iterator2 = _createForOfIteratorHelperLoose(token.tokens.header), _step2; !(_step2 = _iterator2()).done;) {
2593
+ var cell = _step2.value;
2594
+ marked.walkTokens(cell, callback);
2595
+ }
2596
+
2597
+ for (var _iterator3 = _createForOfIteratorHelperLoose(token.tokens.cells), _step3; !(_step3 = _iterator3()).done;) {
2598
+ var row = _step3.value;
2599
+
2600
+ for (var _iterator4 = _createForOfIteratorHelperLoose(row), _step4; !(_step4 = _iterator4()).done;) {
2601
+ var _cell = _step4.value;
2602
+ marked.walkTokens(_cell, callback);
2603
+ }
2604
+ }
2605
+
2606
+ break;
2607
+ }
2608
+
2609
+ case 'list':
2610
+ {
2611
+ marked.walkTokens(token.items, callback);
2612
+ break;
2613
+ }
2614
+
2615
+ default:
2616
+ {
2617
+ if (token.tokens) {
2618
+ marked.walkTokens(token.tokens, callback);
2619
+ }
2620
+ }
2621
+ }
2622
+ }
2623
+ };
2624
+ /**
2625
+ * Parse Inline
2626
+ */
2627
+
2628
+
2629
+ marked.parseInline = function (src, opt) {
2630
+ // throw error in case of non string input
2631
+ if (typeof src === 'undefined' || src === null) {
2632
+ throw new Error('marked.parseInline(): input parameter is undefined or null');
2633
+ }
2634
+
2635
+ if (typeof src !== 'string') {
2636
+ throw new Error('marked.parseInline(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
2637
+ }
2638
+
2639
+ opt = merge$2({}, marked.defaults, opt || {});
2640
+ checkSanitizeDeprecation$1(opt);
2641
+
2642
+ try {
2643
+ var tokens = Lexer_1.lexInline(src, opt);
2644
+
2645
+ if (opt.walkTokens) {
2646
+ marked.walkTokens(tokens, opt.walkTokens);
2647
+ }
2648
+
2649
+ return Parser_1.parseInline(tokens, opt);
2650
+ } catch (e) {
2651
+ e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2652
+
2653
+ if (opt.silent) {
2654
+ return '<p>An error occurred:</p><pre>' + escape$2(e.message + '', true) + '</pre>';
2655
+ }
2656
+
2657
+ throw e;
2658
+ }
2659
+ };
2326
2660
  /**
2327
2661
  * Expose
2328
2662
  */