marked 13.0.1 → 13.0.3

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.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * marked v13.0.1 - a markdown parser
2
+ * marked v13.0.3 - a markdown parser
3
3
  * Copyright (c) 2011-2024, Christopher Jeffrey. (MIT Licensed)
4
4
  * https://github.com/markedjs/marked
5
5
  */
@@ -29,7 +29,7 @@
29
29
  renderer: null,
30
30
  silent: false,
31
31
  tokenizer: null,
32
- walkTokens: null
32
+ walkTokens: null,
33
33
  };
34
34
  }
35
35
  exports.defaults = _getDefaults();
@@ -49,7 +49,7 @@
49
49
  '<': '&lt;',
50
50
  '>': '&gt;',
51
51
  '"': '&quot;',
52
- "'": '&#39;'
52
+ "'": '&#39;',
53
53
  };
54
54
  const getEscapeReplacement = (ch) => escapeReplacements[ch];
55
55
  function escape$1(html, encode) {
@@ -93,7 +93,7 @@
93
93
  },
94
94
  getRegex: () => {
95
95
  return new RegExp(source, opt);
96
- }
96
+ },
97
97
  };
98
98
  return obj;
99
99
  }
@@ -101,7 +101,7 @@
101
101
  try {
102
102
  href = encodeURI(href).replace(/%25/g, '%');
103
103
  }
104
- catch (e) {
104
+ catch {
105
105
  return null;
106
106
  }
107
107
  return href;
@@ -212,7 +212,7 @@
212
212
  href,
213
213
  title,
214
214
  text,
215
- tokens: lexer.inlineTokens(text)
215
+ tokens: lexer.inlineTokens(text),
216
216
  };
217
217
  lexer.state.inLink = false;
218
218
  return token;
@@ -222,7 +222,7 @@
222
222
  raw,
223
223
  href,
224
224
  title,
225
- text: escape$1(text)
225
+ text: escape$1(text),
226
226
  };
227
227
  }
228
228
  function indentCodeCompensation(raw, text) {
@@ -261,7 +261,7 @@
261
261
  if (cap && cap[0].length > 0) {
262
262
  return {
263
263
  type: 'space',
264
- raw: cap[0]
264
+ raw: cap[0],
265
265
  };
266
266
  }
267
267
  }
@@ -275,7 +275,7 @@
275
275
  codeBlockStyle: 'indented',
276
276
  text: !this.options.pedantic
277
277
  ? rtrim(text, '\n')
278
- : text
278
+ : text,
279
279
  };
280
280
  }
281
281
  }
@@ -288,7 +288,7 @@
288
288
  type: 'code',
289
289
  raw,
290
290
  lang: cap[2] ? cap[2].trim().replace(this.rules.inline.anyPunctuation, '$1') : cap[2],
291
- text
291
+ text,
292
292
  };
293
293
  }
294
294
  }
@@ -312,7 +312,7 @@
312
312
  raw: cap[0],
313
313
  depth: cap[1].length,
314
314
  text,
315
- tokens: this.lexer.inline(text)
315
+ tokens: this.lexer.inline(text),
316
316
  };
317
317
  }
318
318
  }
@@ -321,7 +321,7 @@
321
321
  if (cap) {
322
322
  return {
323
323
  type: 'hr',
324
- raw: rtrim(cap[0], '\n')
324
+ raw: rtrim(cap[0], '\n'),
325
325
  };
326
326
  }
327
327
  }
@@ -398,7 +398,7 @@
398
398
  type: 'blockquote',
399
399
  raw,
400
400
  tokens,
401
- text
401
+ text,
402
402
  };
403
403
  }
404
404
  }
@@ -413,7 +413,7 @@
413
413
  ordered: isordered,
414
414
  start: isordered ? +bull.slice(0, -1) : '',
415
415
  loose: false,
416
- items: []
416
+ items: [],
417
417
  };
418
418
  bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
419
419
  if (this.options.pedantic) {
@@ -421,12 +421,12 @@
421
421
  }
422
422
  // Get next list item
423
423
  const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);
424
- let raw = '';
425
- let itemContents = '';
426
424
  let endsWithBlankLine = false;
427
425
  // Check if current bullet point can start a new List Item
428
426
  while (src) {
429
427
  let endEarly = false;
428
+ let raw = '';
429
+ let itemContents = '';
430
430
  if (!(cap = itemRegex.exec(src))) {
431
431
  break;
432
432
  }
@@ -437,19 +437,22 @@
437
437
  src = src.substring(raw.length);
438
438
  let line = cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(3 * t.length));
439
439
  let nextLine = src.split('\n', 1)[0];
440
+ let blankLine = !line.trim();
440
441
  let indent = 0;
441
442
  if (this.options.pedantic) {
442
443
  indent = 2;
443
444
  itemContents = line.trimStart();
444
445
  }
446
+ else if (blankLine) {
447
+ indent = cap[1].length + 1;
448
+ }
445
449
  else {
446
450
  indent = cap[2].search(/[^ ]/); // Find first non-space char
447
451
  indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
448
452
  itemContents = line.slice(indent);
449
453
  indent += cap[1].length;
450
454
  }
451
- let blankLine = false;
452
- if (!line && /^ *$/.test(nextLine)) { // Items begin with at most one blank line
455
+ if (blankLine && /^ *$/.test(nextLine)) { // Items begin with at most one blank line
453
456
  raw += nextLine + '\n';
454
457
  src = src.substring(nextLine.length + 1);
455
458
  endEarly = true;
@@ -540,13 +543,13 @@
540
543
  checked: ischecked,
541
544
  loose: false,
542
545
  text: itemContents,
543
- tokens: []
546
+ tokens: [],
544
547
  });
545
548
  list.raw += raw;
546
549
  }
547
550
  // Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
548
- list.items[list.items.length - 1].raw = raw.trimEnd();
549
- (list.items[list.items.length - 1]).text = itemContents.trimEnd();
551
+ list.items[list.items.length - 1].raw = list.items[list.items.length - 1].raw.trimEnd();
552
+ list.items[list.items.length - 1].text = list.items[list.items.length - 1].text.trimEnd();
550
553
  list.raw = list.raw.trimEnd();
551
554
  // Item child tokens handled here at end because we needed to have the final item to trim it first
552
555
  for (let i = 0; i < list.items.length; i++) {
@@ -576,7 +579,7 @@
576
579
  block: true,
577
580
  raw: cap[0],
578
581
  pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
579
- text: cap[0]
582
+ text: cap[0],
580
583
  };
581
584
  return token;
582
585
  }
@@ -592,7 +595,7 @@
592
595
  tag,
593
596
  raw: cap[0],
594
597
  href,
595
- title
598
+ title,
596
599
  };
597
600
  }
598
601
  }
@@ -613,7 +616,7 @@
613
616
  raw: cap[0],
614
617
  header: [],
615
618
  align: [],
616
- rows: []
619
+ rows: [],
617
620
  };
618
621
  if (headers.length !== aligns.length) {
619
622
  // header and align columns must be equal, rows can be different.
@@ -638,7 +641,7 @@
638
641
  text: headers[i],
639
642
  tokens: this.lexer.inline(headers[i]),
640
643
  header: true,
641
- align: item.align[i]
644
+ align: item.align[i],
642
645
  });
643
646
  }
644
647
  for (const row of rows) {
@@ -647,7 +650,7 @@
647
650
  text: cell,
648
651
  tokens: this.lexer.inline(cell),
649
652
  header: false,
650
- align: item.align[i]
653
+ align: item.align[i],
651
654
  };
652
655
  }));
653
656
  }
@@ -661,7 +664,7 @@
661
664
  raw: cap[0],
662
665
  depth: cap[2].charAt(0) === '=' ? 1 : 2,
663
666
  text: cap[1],
664
- tokens: this.lexer.inline(cap[1])
667
+ tokens: this.lexer.inline(cap[1]),
665
668
  };
666
669
  }
667
670
  }
@@ -675,7 +678,7 @@
675
678
  type: 'paragraph',
676
679
  raw: cap[0],
677
680
  text,
678
- tokens: this.lexer.inline(text)
681
+ tokens: this.lexer.inline(text),
679
682
  };
680
683
  }
681
684
  }
@@ -686,7 +689,7 @@
686
689
  type: 'text',
687
690
  raw: cap[0],
688
691
  text: cap[0],
689
- tokens: this.lexer.inline(cap[0])
692
+ tokens: this.lexer.inline(cap[0]),
690
693
  };
691
694
  }
692
695
  }
@@ -696,7 +699,7 @@
696
699
  return {
697
700
  type: 'escape',
698
701
  raw: cap[0],
699
- text: escape$1(cap[1])
702
+ text: escape$1(cap[1]),
700
703
  };
701
704
  }
702
705
  }
@@ -721,7 +724,7 @@
721
724
  inLink: this.lexer.state.inLink,
722
725
  inRawBlock: this.lexer.state.inRawBlock,
723
726
  block: false,
724
- text: cap[0]
727
+ text: cap[0],
725
728
  };
726
729
  }
727
730
  }
@@ -776,7 +779,7 @@
776
779
  }
777
780
  return outputLink(cap, {
778
781
  href: href ? href.replace(this.rules.inline.anyPunctuation, '$1') : href,
779
- title: title ? title.replace(this.rules.inline.anyPunctuation, '$1') : title
782
+ title: title ? title.replace(this.rules.inline.anyPunctuation, '$1') : title,
780
783
  }, cap[0], this.lexer);
781
784
  }
782
785
  }
@@ -791,7 +794,7 @@
791
794
  return {
792
795
  type: 'text',
793
796
  raw: text,
794
- text
797
+ text,
795
798
  };
796
799
  }
797
800
  return outputLink(cap, link, cap[0], this.lexer);
@@ -843,7 +846,7 @@
843
846
  type: 'em',
844
847
  raw,
845
848
  text,
846
- tokens: this.lexer.inlineTokens(text)
849
+ tokens: this.lexer.inlineTokens(text),
847
850
  };
848
851
  }
849
852
  // Create 'strong' if smallest delimiter has even char count. **a***
@@ -852,7 +855,7 @@
852
855
  type: 'strong',
853
856
  raw,
854
857
  text,
855
- tokens: this.lexer.inlineTokens(text)
858
+ tokens: this.lexer.inlineTokens(text),
856
859
  };
857
860
  }
858
861
  }
@@ -870,7 +873,7 @@
870
873
  return {
871
874
  type: 'codespan',
872
875
  raw: cap[0],
873
- text
876
+ text,
874
877
  };
875
878
  }
876
879
  }
@@ -879,7 +882,7 @@
879
882
  if (cap) {
880
883
  return {
881
884
  type: 'br',
882
- raw: cap[0]
885
+ raw: cap[0],
883
886
  };
884
887
  }
885
888
  }
@@ -890,7 +893,7 @@
890
893
  type: 'del',
891
894
  raw: cap[0],
892
895
  text: cap[2],
893
- tokens: this.lexer.inlineTokens(cap[2])
896
+ tokens: this.lexer.inlineTokens(cap[2]),
894
897
  };
895
898
  }
896
899
  }
@@ -915,9 +918,9 @@
915
918
  {
916
919
  type: 'text',
917
920
  raw: text,
918
- text
919
- }
920
- ]
921
+ text,
922
+ },
923
+ ],
921
924
  };
922
925
  }
923
926
  }
@@ -953,9 +956,9 @@
953
956
  {
954
957
  type: 'text',
955
958
  raw: text,
956
- text
957
- }
958
- ]
959
+ text,
960
+ },
961
+ ],
959
962
  };
960
963
  }
961
964
  }
@@ -972,7 +975,7 @@
972
975
  return {
973
976
  type: 'text',
974
977
  raw: cap[0],
975
- text
978
+ text,
976
979
  };
977
980
  }
978
981
  }
@@ -1056,7 +1059,7 @@
1056
1059
  newline,
1057
1060
  paragraph,
1058
1061
  table: noopTest,
1059
- text: blockText
1062
+ text: blockText,
1060
1063
  };
1061
1064
  /**
1062
1065
  * GFM Block Grammar
@@ -1086,7 +1089,7 @@
1086
1089
  .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1087
1090
  .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1088
1091
  .replace('tag', _tag) // pars can be interrupted by type (6) html blocks
1089
- .getRegex()
1092
+ .getRegex(),
1090
1093
  };
1091
1094
  /**
1092
1095
  * Pedantic grammar (original John Gruber's loose markdown specification)
@@ -1116,7 +1119,7 @@
1116
1119
  .replace('|list', '')
1117
1120
  .replace('|html', '')
1118
1121
  .replace('|tag', '')
1119
- .getRegex()
1122
+ .getRegex(),
1120
1123
  };
1121
1124
  /**
1122
1125
  * Inline-Level Grammar
@@ -1210,7 +1213,7 @@
1210
1213
  reflinkSearch,
1211
1214
  tag,
1212
1215
  text: inlineText,
1213
- url: noopTest
1216
+ url: noopTest,
1214
1217
  };
1215
1218
  /**
1216
1219
  * Pedantic Inline Grammar
@@ -1222,7 +1225,7 @@
1222
1225
  .getRegex(),
1223
1226
  reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
1224
1227
  .replace('label', _inlineLabel)
1225
- .getRegex()
1228
+ .getRegex(),
1226
1229
  };
1227
1230
  /**
1228
1231
  * GFM Inline Grammar
@@ -1235,7 +1238,7 @@
1235
1238
  .getRegex(),
1236
1239
  _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
1237
1240
  del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
1238
- text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
1241
+ text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/,
1239
1242
  };
1240
1243
  /**
1241
1244
  * GFM + Line Breaks Inline Grammar
@@ -1246,7 +1249,7 @@
1246
1249
  text: edit(inlineGfm.text)
1247
1250
  .replace('\\b_', '\\b_| {2,}\\n')
1248
1251
  .replace(/\{2,\}/g, '*')
1249
- .getRegex()
1252
+ .getRegex(),
1250
1253
  };
1251
1254
  /**
1252
1255
  * exports
@@ -1254,13 +1257,13 @@
1254
1257
  const block = {
1255
1258
  normal: blockNormal,
1256
1259
  gfm: blockGfm,
1257
- pedantic: blockPedantic
1260
+ pedantic: blockPedantic,
1258
1261
  };
1259
1262
  const inline = {
1260
1263
  normal: inlineNormal,
1261
1264
  gfm: inlineGfm,
1262
1265
  breaks: inlineBreaks,
1263
- pedantic: inlinePedantic
1266
+ pedantic: inlinePedantic,
1264
1267
  };
1265
1268
 
1266
1269
  /**
@@ -1285,11 +1288,11 @@
1285
1288
  this.state = {
1286
1289
  inLink: false,
1287
1290
  inRawBlock: false,
1288
- top: true
1291
+ top: true,
1289
1292
  };
1290
1293
  const rules = {
1291
1294
  block: block.normal,
1292
- inline: inline.normal
1295
+ inline: inline.normal,
1293
1296
  };
1294
1297
  if (this.options.pedantic) {
1295
1298
  rules.block = block.pedantic;
@@ -1312,7 +1315,7 @@
1312
1315
  static get rules() {
1313
1316
  return {
1314
1317
  block,
1315
- inline
1318
+ inline,
1316
1319
  };
1317
1320
  }
1318
1321
  /**
@@ -1444,7 +1447,7 @@
1444
1447
  else if (!this.tokens.links[token.tag]) {
1445
1448
  this.tokens.links[token.tag] = {
1446
1449
  href: token.href,
1447
- title: token.title
1450
+ title: token.title,
1448
1451
  };
1449
1452
  }
1450
1453
  continue;
@@ -1760,7 +1763,7 @@
1760
1763
  item.tokens.unshift({
1761
1764
  type: 'text',
1762
1765
  raw: checkbox + ' ',
1763
- text: checkbox + ' '
1766
+ text: checkbox + ' ',
1764
1767
  });
1765
1768
  }
1766
1769
  }
@@ -1996,7 +1999,7 @@
1996
1999
  type: 'paragraph',
1997
2000
  raw: body,
1998
2001
  text: body,
1999
- tokens: [{ type: 'text', raw: body, text: body }]
2002
+ tokens: [{ type: 'text', raw: body, text: body }],
2000
2003
  });
2001
2004
  }
2002
2005
  else {
@@ -2100,7 +2103,7 @@
2100
2103
  static passThroughHooks = new Set([
2101
2104
  'preprocess',
2102
2105
  'postprocess',
2103
- 'processAllTokens'
2106
+ 'processAllTokens',
2104
2107
  ]);
2105
2108
  /**
2106
2109
  * Process markdown before marked
@@ -2255,13 +2258,13 @@
2255
2258
  }
2256
2259
  const rendererProp = prop;
2257
2260
  let rendererFunc = pack.renderer[rendererProp];
2261
+ if (!pack.useNewRenderer) {
2262
+ // TODO: Remove this in next major version
2263
+ rendererFunc = this.#convertRendererFunction(rendererFunc, rendererProp, renderer);
2264
+ }
2258
2265
  const prevRenderer = renderer[rendererProp];
2259
2266
  // Replace renderer with func to run extension, but fall back if false
2260
2267
  renderer[rendererProp] = (...args) => {
2261
- if (!pack.useNewRenderer) {
2262
- // TODO: Remove this in next major version
2263
- rendererFunc = this.#convertRendererFunction(rendererFunc, rendererProp, renderer);
2264
- }
2265
2268
  let ret = rendererFunc.apply(renderer, args);
2266
2269
  if (ret === false) {
2267
2270
  ret = prevRenderer.apply(renderer, args);
@@ -2388,7 +2391,7 @@
2388
2391
  text: token.header[j].text,
2389
2392
  tokens: token.header[j].tokens,
2390
2393
  header: true,
2391
- align: token.align[j]
2394
+ align: token.align[j],
2392
2395
  });
2393
2396
  }
2394
2397
  header += this.tablerow({ text: cell });
@@ -2401,7 +2404,7 @@
2401
2404
  text: row[k].text,
2402
2405
  tokens: row[k].tokens,
2403
2406
  header: false,
2404
- align: token.align[k]
2407
+ align: token.align[k],
2405
2408
  });
2406
2409
  }
2407
2410
  body += this.tablerow({ text: cell });
@@ -2446,7 +2449,7 @@
2446
2449
  else {
2447
2450
  item.tokens.unshift({
2448
2451
  type: 'text',
2449
- text: checkbox + ' '
2452
+ text: checkbox + ' ',
2450
2453
  });
2451
2454
  }
2452
2455
  }
@@ -2462,7 +2465,7 @@
2462
2465
  task,
2463
2466
  checked: !!checked,
2464
2467
  loose,
2465
- tokens: item.tokens
2468
+ tokens: item.tokens,
2466
2469
  });
2467
2470
  }
2468
2471
  return func.call(this, body, ordered, start);