marked 14.1.0 → 14.1.2

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 v14.1.0 - a markdown parser
2
+ * marked v14.1.2 - a markdown parser
3
3
  * Copyright (c) 2011-2024, Christopher Jeffrey. (MIT Licensed)
4
4
  * https://github.com/markedjs/marked
5
5
  */
@@ -253,7 +253,7 @@
253
253
  code(src) {
254
254
  const cap = this.rules.block.code.exec(src);
255
255
  if (cap) {
256
- const text = cap[0].replace(/^ {1,4}/gm, '');
256
+ const text = cap[0].replace(/^(?: {1,4}| {0,3}\t)/gm, '');
257
257
  return {
258
258
  type: 'code',
259
259
  raw: cap[0],
@@ -437,7 +437,7 @@
437
437
  itemContents = line.slice(indent);
438
438
  indent += cap[1].length;
439
439
  }
440
- if (blankLine && /^ *$/.test(nextLine)) { // Items begin with at most one blank line
440
+ if (blankLine && /^[ \t]*$/.test(nextLine)) { // Items begin with at most one blank line
441
441
  raw += nextLine + '\n';
442
442
  src = src.substring(nextLine.length + 1);
443
443
  endEarly = true;
@@ -447,13 +447,19 @@
447
447
  const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
448
448
  const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
449
449
  const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
450
+ const htmlBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}<[a-z].*>`, 'i');
450
451
  // Check if following lines should be included in List Item
451
452
  while (src) {
452
453
  const rawLine = src.split('\n', 1)[0];
454
+ let nextLineWithoutTabs;
453
455
  nextLine = rawLine;
454
456
  // Re-align to follow commonmark nesting rules
455
457
  if (this.options.pedantic) {
456
458
  nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
459
+ nextLineWithoutTabs = nextLine;
460
+ }
461
+ else {
462
+ nextLineWithoutTabs = nextLine.replace(/\t/g, ' ');
457
463
  }
458
464
  // End list item if found code fences
459
465
  if (fencesBeginRegex.test(nextLine)) {
@@ -463,16 +469,20 @@
463
469
  if (headingBeginRegex.test(nextLine)) {
464
470
  break;
465
471
  }
472
+ // End list item if found start of html block
473
+ if (htmlBeginRegex.test(nextLine)) {
474
+ break;
475
+ }
466
476
  // End list item if found start of new bullet
467
477
  if (nextBulletRegex.test(nextLine)) {
468
478
  break;
469
479
  }
470
480
  // Horizontal rule found
471
- if (hrRegex.test(src)) {
481
+ if (hrRegex.test(nextLine)) {
472
482
  break;
473
483
  }
474
- if (nextLine.search(/[^ ]/) >= indent || !nextLine.trim()) { // Dedent if possible
475
- itemContents += '\n' + nextLine.slice(indent);
484
+ if (nextLineWithoutTabs.search(/[^ ]/) >= indent || !nextLine.trim()) { // Dedent if possible
485
+ itemContents += '\n' + nextLineWithoutTabs.slice(indent);
476
486
  }
477
487
  else {
478
488
  // not enough indentation
@@ -480,7 +490,7 @@
480
490
  break;
481
491
  }
482
492
  // paragraph continuation unless last line was a different block level element
483
- if (line.search(/[^ ]/) >= 4) { // indented code block
493
+ if (line.replace(/\t/g, ' ').search(/[^ ]/) >= 4) { // indented code block
484
494
  break;
485
495
  }
486
496
  if (fencesBeginRegex.test(line)) {
@@ -499,7 +509,7 @@
499
509
  }
500
510
  raw += rawLine + '\n';
501
511
  src = src.substring(rawLine.length + 1);
502
- line = nextLine.slice(indent);
512
+ line = nextLineWithoutTabs.slice(indent);
503
513
  }
504
514
  }
505
515
  if (!list.loose) {
@@ -507,7 +517,7 @@
507
517
  if (endsWithBlankLine) {
508
518
  list.loose = true;
509
519
  }
510
- else if (/\n *\n *$/.test(raw)) {
520
+ else if (/\n[ \t]*\n[ \t]*$/.test(raw)) {
511
521
  endsWithBlankLine = true;
512
522
  }
513
523
  }
@@ -969,15 +979,15 @@
969
979
  /**
970
980
  * Block-Level Grammar
971
981
  */
972
- const newline = /^(?: *(?:\n|$))+/;
973
- const blockCode = /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/;
982
+ const newline = /^(?:[ \t]*(?:\n|$))+/;
983
+ const blockCode = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
974
984
  const fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
975
985
  const hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
976
986
  const heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
977
987
  const bullet = /(?:[*+-]|\d{1,9}[.)])/;
978
988
  const lheading = edit(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/)
979
989
  .replace(/bull/g, bullet) // lists can interrupt
980
- .replace(/blockCode/g, / {4}/) // indented code blocks can interrupt
990
+ .replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
981
991
  .replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
982
992
  .replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
983
993
  .replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
@@ -986,7 +996,7 @@
986
996
  const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
987
997
  const blockText = /^[^\n]+/;
988
998
  const _blockLabel = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
989
- const def = edit(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/)
999
+ const def = edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/)
990
1000
  .replace('label', _blockLabel)
991
1001
  .replace('title', /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/)
992
1002
  .getRegex();
@@ -1006,9 +1016,9 @@
1006
1016
  + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
1007
1017
  + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
1008
1018
  + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
1009
- + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (6)
1010
- + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
1011
- + '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
1019
+ + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (6)
1020
+ + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (7) open tag
1021
+ + '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (7) closing tag
1012
1022
  + ')', 'i')
1013
1023
  .replace('comment', _comment)
1014
1024
  .replace('tag', _tag)
@@ -1055,7 +1065,7 @@
1055
1065
  .replace('hr', hr)
1056
1066
  .replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
1057
1067
  .replace('blockquote', ' {0,3}>')
1058
- .replace('code', ' {4}[^\\n]')
1068
+ .replace('code', '(?: {4}| {0,3}\t)[^\\n]')
1059
1069
  .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1060
1070
  .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1061
1071
  .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
@@ -1335,11 +1345,6 @@
1335
1345
  if (this.options.pedantic) {
1336
1346
  src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
1337
1347
  }
1338
- else {
1339
- src = src.replace(/^( *)(\t+)/gm, (_, leading, tabs) => {
1340
- return leading + ' '.repeat(tabs.length);
1341
- });
1342
- }
1343
1348
  let token;
1344
1349
  let lastToken;
1345
1350
  let cutSrc;