marked 13.0.2 → 14.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.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * marked v13.0.2 - a markdown parser
2
+ * marked v14.0.0 - a markdown parser
3
3
  * Copyright (c) 2011-2024, Christopher Jeffrey. (MIT Licensed)
4
4
  * https://github.com/markedjs/marked
5
5
  */
@@ -25,7 +25,7 @@ function _getDefaults() {
25
25
  renderer: null,
26
26
  silent: false,
27
27
  tokenizer: null,
28
- walkTokens: null
28
+ walkTokens: null,
29
29
  };
30
30
  }
31
31
  exports.defaults = _getDefaults();
@@ -45,7 +45,7 @@ const escapeReplacements = {
45
45
  '<': '&lt;',
46
46
  '>': '&gt;',
47
47
  '"': '&quot;',
48
- "'": '&#39;'
48
+ "'": '&#39;',
49
49
  };
50
50
  const getEscapeReplacement = (ch) => escapeReplacements[ch];
51
51
  function escape$1(html, encode) {
@@ -61,21 +61,6 @@ function escape$1(html, encode) {
61
61
  }
62
62
  return html;
63
63
  }
64
- const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
65
- function unescape(html) {
66
- // explicitly match decimal, hex, and named HTML entities
67
- return html.replace(unescapeTest, (_, n) => {
68
- n = n.toLowerCase();
69
- if (n === 'colon')
70
- return ':';
71
- if (n.charAt(0) === '#') {
72
- return n.charAt(1) === 'x'
73
- ? String.fromCharCode(parseInt(n.substring(2), 16))
74
- : String.fromCharCode(+n.substring(1));
75
- }
76
- return '';
77
- });
78
- }
79
64
  const caret = /(^|[^\[])\^/g;
80
65
  function edit(regex, opt) {
81
66
  let source = typeof regex === 'string' ? regex : regex.source;
@@ -89,7 +74,7 @@ function edit(regex, opt) {
89
74
  },
90
75
  getRegex: () => {
91
76
  return new RegExp(source, opt);
92
- }
77
+ },
93
78
  };
94
79
  return obj;
95
80
  }
@@ -97,7 +82,7 @@ function cleanUrl(href) {
97
82
  try {
98
83
  href = encodeURI(href).replace(/%25/g, '%');
99
84
  }
100
- catch (e) {
85
+ catch {
101
86
  return null;
102
87
  }
103
88
  return href;
@@ -208,7 +193,7 @@ function outputLink(cap, link, raw, lexer) {
208
193
  href,
209
194
  title,
210
195
  text,
211
- tokens: lexer.inlineTokens(text)
196
+ tokens: lexer.inlineTokens(text),
212
197
  };
213
198
  lexer.state.inLink = false;
214
199
  return token;
@@ -218,7 +203,7 @@ function outputLink(cap, link, raw, lexer) {
218
203
  raw,
219
204
  href,
220
205
  title,
221
- text: escape$1(text)
206
+ text: escape$1(text),
222
207
  };
223
208
  }
224
209
  function indentCodeCompensation(raw, text) {
@@ -257,7 +242,7 @@ class _Tokenizer {
257
242
  if (cap && cap[0].length > 0) {
258
243
  return {
259
244
  type: 'space',
260
- raw: cap[0]
245
+ raw: cap[0],
261
246
  };
262
247
  }
263
248
  }
@@ -271,7 +256,7 @@ class _Tokenizer {
271
256
  codeBlockStyle: 'indented',
272
257
  text: !this.options.pedantic
273
258
  ? rtrim(text, '\n')
274
- : text
259
+ : text,
275
260
  };
276
261
  }
277
262
  }
@@ -284,7 +269,7 @@ class _Tokenizer {
284
269
  type: 'code',
285
270
  raw,
286
271
  lang: cap[2] ? cap[2].trim().replace(this.rules.inline.anyPunctuation, '$1') : cap[2],
287
- text
272
+ text,
288
273
  };
289
274
  }
290
275
  }
@@ -308,7 +293,7 @@ class _Tokenizer {
308
293
  raw: cap[0],
309
294
  depth: cap[1].length,
310
295
  text,
311
- tokens: this.lexer.inline(text)
296
+ tokens: this.lexer.inline(text),
312
297
  };
313
298
  }
314
299
  }
@@ -317,7 +302,7 @@ class _Tokenizer {
317
302
  if (cap) {
318
303
  return {
319
304
  type: 'hr',
320
- raw: rtrim(cap[0], '\n')
305
+ raw: rtrim(cap[0], '\n'),
321
306
  };
322
307
  }
323
308
  }
@@ -394,7 +379,7 @@ class _Tokenizer {
394
379
  type: 'blockquote',
395
380
  raw,
396
381
  tokens,
397
- text
382
+ text,
398
383
  };
399
384
  }
400
385
  }
@@ -409,7 +394,7 @@ class _Tokenizer {
409
394
  ordered: isordered,
410
395
  start: isordered ? +bull.slice(0, -1) : '',
411
396
  loose: false,
412
- items: []
397
+ items: [],
413
398
  };
414
399
  bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
415
400
  if (this.options.pedantic) {
@@ -539,7 +524,7 @@ class _Tokenizer {
539
524
  checked: ischecked,
540
525
  loose: false,
541
526
  text: itemContents,
542
- tokens: []
527
+ tokens: [],
543
528
  });
544
529
  list.raw += raw;
545
530
  }
@@ -575,7 +560,7 @@ class _Tokenizer {
575
560
  block: true,
576
561
  raw: cap[0],
577
562
  pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
578
- text: cap[0]
563
+ text: cap[0],
579
564
  };
580
565
  return token;
581
566
  }
@@ -591,7 +576,7 @@ class _Tokenizer {
591
576
  tag,
592
577
  raw: cap[0],
593
578
  href,
594
- title
579
+ title,
595
580
  };
596
581
  }
597
582
  }
@@ -612,7 +597,7 @@ class _Tokenizer {
612
597
  raw: cap[0],
613
598
  header: [],
614
599
  align: [],
615
- rows: []
600
+ rows: [],
616
601
  };
617
602
  if (headers.length !== aligns.length) {
618
603
  // header and align columns must be equal, rows can be different.
@@ -637,7 +622,7 @@ class _Tokenizer {
637
622
  text: headers[i],
638
623
  tokens: this.lexer.inline(headers[i]),
639
624
  header: true,
640
- align: item.align[i]
625
+ align: item.align[i],
641
626
  });
642
627
  }
643
628
  for (const row of rows) {
@@ -646,7 +631,7 @@ class _Tokenizer {
646
631
  text: cell,
647
632
  tokens: this.lexer.inline(cell),
648
633
  header: false,
649
- align: item.align[i]
634
+ align: item.align[i],
650
635
  };
651
636
  }));
652
637
  }
@@ -660,7 +645,7 @@ class _Tokenizer {
660
645
  raw: cap[0],
661
646
  depth: cap[2].charAt(0) === '=' ? 1 : 2,
662
647
  text: cap[1],
663
- tokens: this.lexer.inline(cap[1])
648
+ tokens: this.lexer.inline(cap[1]),
664
649
  };
665
650
  }
666
651
  }
@@ -674,7 +659,7 @@ class _Tokenizer {
674
659
  type: 'paragraph',
675
660
  raw: cap[0],
676
661
  text,
677
- tokens: this.lexer.inline(text)
662
+ tokens: this.lexer.inline(text),
678
663
  };
679
664
  }
680
665
  }
@@ -685,7 +670,7 @@ class _Tokenizer {
685
670
  type: 'text',
686
671
  raw: cap[0],
687
672
  text: cap[0],
688
- tokens: this.lexer.inline(cap[0])
673
+ tokens: this.lexer.inline(cap[0]),
689
674
  };
690
675
  }
691
676
  }
@@ -695,7 +680,7 @@ class _Tokenizer {
695
680
  return {
696
681
  type: 'escape',
697
682
  raw: cap[0],
698
- text: escape$1(cap[1])
683
+ text: escape$1(cap[1]),
699
684
  };
700
685
  }
701
686
  }
@@ -720,7 +705,7 @@ class _Tokenizer {
720
705
  inLink: this.lexer.state.inLink,
721
706
  inRawBlock: this.lexer.state.inRawBlock,
722
707
  block: false,
723
- text: cap[0]
708
+ text: cap[0],
724
709
  };
725
710
  }
726
711
  }
@@ -775,7 +760,7 @@ class _Tokenizer {
775
760
  }
776
761
  return outputLink(cap, {
777
762
  href: href ? href.replace(this.rules.inline.anyPunctuation, '$1') : href,
778
- title: title ? title.replace(this.rules.inline.anyPunctuation, '$1') : title
763
+ title: title ? title.replace(this.rules.inline.anyPunctuation, '$1') : title,
779
764
  }, cap[0], this.lexer);
780
765
  }
781
766
  }
@@ -790,7 +775,7 @@ class _Tokenizer {
790
775
  return {
791
776
  type: 'text',
792
777
  raw: text,
793
- text
778
+ text,
794
779
  };
795
780
  }
796
781
  return outputLink(cap, link, cap[0], this.lexer);
@@ -842,7 +827,7 @@ class _Tokenizer {
842
827
  type: 'em',
843
828
  raw,
844
829
  text,
845
- tokens: this.lexer.inlineTokens(text)
830
+ tokens: this.lexer.inlineTokens(text),
846
831
  };
847
832
  }
848
833
  // Create 'strong' if smallest delimiter has even char count. **a***
@@ -851,7 +836,7 @@ class _Tokenizer {
851
836
  type: 'strong',
852
837
  raw,
853
838
  text,
854
- tokens: this.lexer.inlineTokens(text)
839
+ tokens: this.lexer.inlineTokens(text),
855
840
  };
856
841
  }
857
842
  }
@@ -869,7 +854,7 @@ class _Tokenizer {
869
854
  return {
870
855
  type: 'codespan',
871
856
  raw: cap[0],
872
- text
857
+ text,
873
858
  };
874
859
  }
875
860
  }
@@ -878,7 +863,7 @@ class _Tokenizer {
878
863
  if (cap) {
879
864
  return {
880
865
  type: 'br',
881
- raw: cap[0]
866
+ raw: cap[0],
882
867
  };
883
868
  }
884
869
  }
@@ -889,7 +874,7 @@ class _Tokenizer {
889
874
  type: 'del',
890
875
  raw: cap[0],
891
876
  text: cap[2],
892
- tokens: this.lexer.inlineTokens(cap[2])
877
+ tokens: this.lexer.inlineTokens(cap[2]),
893
878
  };
894
879
  }
895
880
  }
@@ -914,9 +899,9 @@ class _Tokenizer {
914
899
  {
915
900
  type: 'text',
916
901
  raw: text,
917
- text
918
- }
919
- ]
902
+ text,
903
+ },
904
+ ],
920
905
  };
921
906
  }
922
907
  }
@@ -952,9 +937,9 @@ class _Tokenizer {
952
937
  {
953
938
  type: 'text',
954
939
  raw: text,
955
- text
956
- }
957
- ]
940
+ text,
941
+ },
942
+ ],
958
943
  };
959
944
  }
960
945
  }
@@ -971,7 +956,7 @@ class _Tokenizer {
971
956
  return {
972
957
  type: 'text',
973
958
  raw: cap[0],
974
- text
959
+ text,
975
960
  };
976
961
  }
977
962
  }
@@ -1055,7 +1040,7 @@ const blockNormal = {
1055
1040
  newline,
1056
1041
  paragraph,
1057
1042
  table: noopTest,
1058
- text: blockText
1043
+ text: blockText,
1059
1044
  };
1060
1045
  /**
1061
1046
  * GFM Block Grammar
@@ -1085,7 +1070,7 @@ const blockGfm = {
1085
1070
  .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1086
1071
  .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1087
1072
  .replace('tag', _tag) // pars can be interrupted by type (6) html blocks
1088
- .getRegex()
1073
+ .getRegex(),
1089
1074
  };
1090
1075
  /**
1091
1076
  * Pedantic grammar (original John Gruber's loose markdown specification)
@@ -1115,7 +1100,7 @@ const blockPedantic = {
1115
1100
  .replace('|list', '')
1116
1101
  .replace('|html', '')
1117
1102
  .replace('|tag', '')
1118
- .getRegex()
1103
+ .getRegex(),
1119
1104
  };
1120
1105
  /**
1121
1106
  * Inline-Level Grammar
@@ -1209,7 +1194,7 @@ const inlineNormal = {
1209
1194
  reflinkSearch,
1210
1195
  tag,
1211
1196
  text: inlineText,
1212
- url: noopTest
1197
+ url: noopTest,
1213
1198
  };
1214
1199
  /**
1215
1200
  * Pedantic Inline Grammar
@@ -1221,7 +1206,7 @@ const inlinePedantic = {
1221
1206
  .getRegex(),
1222
1207
  reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
1223
1208
  .replace('label', _inlineLabel)
1224
- .getRegex()
1209
+ .getRegex(),
1225
1210
  };
1226
1211
  /**
1227
1212
  * GFM Inline Grammar
@@ -1234,7 +1219,7 @@ const inlineGfm = {
1234
1219
  .getRegex(),
1235
1220
  _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
1236
1221
  del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
1237
- text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
1222
+ text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/,
1238
1223
  };
1239
1224
  /**
1240
1225
  * GFM + Line Breaks Inline Grammar
@@ -1245,7 +1230,7 @@ const inlineBreaks = {
1245
1230
  text: edit(inlineGfm.text)
1246
1231
  .replace('\\b_', '\\b_| {2,}\\n')
1247
1232
  .replace(/\{2,\}/g, '*')
1248
- .getRegex()
1233
+ .getRegex(),
1249
1234
  };
1250
1235
  /**
1251
1236
  * exports
@@ -1253,13 +1238,13 @@ const inlineBreaks = {
1253
1238
  const block = {
1254
1239
  normal: blockNormal,
1255
1240
  gfm: blockGfm,
1256
- pedantic: blockPedantic
1241
+ pedantic: blockPedantic,
1257
1242
  };
1258
1243
  const inline = {
1259
1244
  normal: inlineNormal,
1260
1245
  gfm: inlineGfm,
1261
1246
  breaks: inlineBreaks,
1262
- pedantic: inlinePedantic
1247
+ pedantic: inlinePedantic,
1263
1248
  };
1264
1249
 
1265
1250
  /**
@@ -1284,11 +1269,11 @@ class _Lexer {
1284
1269
  this.state = {
1285
1270
  inLink: false,
1286
1271
  inRawBlock: false,
1287
- top: true
1272
+ top: true,
1288
1273
  };
1289
1274
  const rules = {
1290
1275
  block: block.normal,
1291
- inline: inline.normal
1276
+ inline: inline.normal,
1292
1277
  };
1293
1278
  if (this.options.pedantic) {
1294
1279
  rules.block = block.pedantic;
@@ -1311,7 +1296,7 @@ class _Lexer {
1311
1296
  static get rules() {
1312
1297
  return {
1313
1298
  block,
1314
- inline
1299
+ inline,
1315
1300
  };
1316
1301
  }
1317
1302
  /**
@@ -1443,7 +1428,7 @@ class _Lexer {
1443
1428
  else if (!this.tokens.links[token.tag]) {
1444
1429
  this.tokens.links[token.tag] = {
1445
1430
  href: token.href,
1446
- title: token.title
1431
+ title: token.title,
1447
1432
  };
1448
1433
  }
1449
1434
  continue;
@@ -1759,7 +1744,7 @@ class _Renderer {
1759
1744
  item.tokens.unshift({
1760
1745
  type: 'text',
1761
1746
  raw: checkbox + ' ',
1762
- text: checkbox + ' '
1747
+ text: checkbox + ' ',
1763
1748
  });
1764
1749
  }
1765
1750
  }
@@ -1995,7 +1980,7 @@ class _Parser {
1995
1980
  type: 'paragraph',
1996
1981
  raw: body,
1997
1982
  text: body,
1998
- tokens: [{ type: 'text', raw: body, text: body }]
1983
+ tokens: [{ type: 'text', raw: body, text: body }],
1999
1984
  });
2000
1985
  }
2001
1986
  else {
@@ -2099,7 +2084,7 @@ class _Hooks {
2099
2084
  static passThroughHooks = new Set([
2100
2085
  'preprocess',
2101
2086
  'postprocess',
2102
- 'processAllTokens'
2087
+ 'processAllTokens',
2103
2088
  ]);
2104
2089
  /**
2105
2090
  * Process markdown before marked
@@ -2124,8 +2109,8 @@ class _Hooks {
2124
2109
  class Marked {
2125
2110
  defaults = _getDefaults();
2126
2111
  options = this.setOptions;
2127
- parse = this.#parseMarkdown(_Lexer.lex, _Parser.parse);
2128
- parseInline = this.#parseMarkdown(_Lexer.lexInline, _Parser.parseInline);
2112
+ parse = this.parseMarkdown(_Lexer.lex, _Parser.parse);
2113
+ parseInline = this.parseMarkdown(_Lexer.lexInline, _Parser.parseInline);
2129
2114
  Parser = _Parser;
2130
2115
  Renderer = _Renderer;
2131
2116
  TextRenderer = _TextRenderer;
@@ -2253,14 +2238,10 @@ class Marked {
2253
2238
  continue;
2254
2239
  }
2255
2240
  const rendererProp = prop;
2256
- let rendererFunc = pack.renderer[rendererProp];
2241
+ const rendererFunc = pack.renderer[rendererProp];
2257
2242
  const prevRenderer = renderer[rendererProp];
2258
2243
  // Replace renderer with func to run extension, but fall back if false
2259
2244
  renderer[rendererProp] = (...args) => {
2260
- if (!pack.useNewRenderer) {
2261
- // TODO: Remove this in next major version
2262
- rendererFunc = this.#convertRendererFunction(rendererFunc, rendererProp, renderer);
2263
- }
2264
2245
  let ret = rendererFunc.apply(renderer, args);
2265
2246
  if (ret === false) {
2266
2247
  ret = prevRenderer.apply(renderer, args);
@@ -2351,215 +2332,6 @@ class Marked {
2351
2332
  });
2352
2333
  return this;
2353
2334
  }
2354
- // TODO: Remove this in next major release
2355
- #convertRendererFunction(func, prop, renderer) {
2356
- switch (prop) {
2357
- case 'heading':
2358
- return function (token) {
2359
- if (!token.type || token.type !== prop) {
2360
- // @ts-ignore
2361
- // eslint-disable-next-line prefer-rest-params
2362
- return func.apply(this, arguments);
2363
- }
2364
- return func.call(this, renderer.parser.parseInline(token.tokens), token.depth, unescape(renderer.parser.parseInline(token.tokens, renderer.parser.textRenderer)));
2365
- };
2366
- case 'code':
2367
- return function (token) {
2368
- if (!token.type || token.type !== prop) {
2369
- // @ts-ignore
2370
- // eslint-disable-next-line prefer-rest-params
2371
- return func.apply(this, arguments);
2372
- }
2373
- return func.call(this, token.text, token.lang, !!token.escaped);
2374
- };
2375
- case 'table':
2376
- return function (token) {
2377
- if (!token.type || token.type !== prop) {
2378
- // @ts-ignore
2379
- // eslint-disable-next-line prefer-rest-params
2380
- return func.apply(this, arguments);
2381
- }
2382
- let header = '';
2383
- // header
2384
- let cell = '';
2385
- for (let j = 0; j < token.header.length; j++) {
2386
- cell += this.tablecell({
2387
- text: token.header[j].text,
2388
- tokens: token.header[j].tokens,
2389
- header: true,
2390
- align: token.align[j]
2391
- });
2392
- }
2393
- header += this.tablerow({ text: cell });
2394
- let body = '';
2395
- for (let j = 0; j < token.rows.length; j++) {
2396
- const row = token.rows[j];
2397
- cell = '';
2398
- for (let k = 0; k < row.length; k++) {
2399
- cell += this.tablecell({
2400
- text: row[k].text,
2401
- tokens: row[k].tokens,
2402
- header: false,
2403
- align: token.align[k]
2404
- });
2405
- }
2406
- body += this.tablerow({ text: cell });
2407
- }
2408
- return func.call(this, header, body);
2409
- };
2410
- case 'blockquote':
2411
- return function (token) {
2412
- if (!token.type || token.type !== prop) {
2413
- // @ts-ignore
2414
- // eslint-disable-next-line prefer-rest-params
2415
- return func.apply(this, arguments);
2416
- }
2417
- const body = this.parser.parse(token.tokens);
2418
- return func.call(this, body);
2419
- };
2420
- case 'list':
2421
- return function (token) {
2422
- if (!token.type || token.type !== prop) {
2423
- // @ts-ignore
2424
- // eslint-disable-next-line prefer-rest-params
2425
- return func.apply(this, arguments);
2426
- }
2427
- const ordered = token.ordered;
2428
- const start = token.start;
2429
- const loose = token.loose;
2430
- let body = '';
2431
- for (let j = 0; j < token.items.length; j++) {
2432
- const item = token.items[j];
2433
- const checked = item.checked;
2434
- const task = item.task;
2435
- let itemBody = '';
2436
- if (item.task) {
2437
- const checkbox = this.checkbox({ checked: !!checked });
2438
- if (loose) {
2439
- if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
2440
- item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
2441
- if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
2442
- item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
2443
- }
2444
- }
2445
- else {
2446
- item.tokens.unshift({
2447
- type: 'text',
2448
- text: checkbox + ' '
2449
- });
2450
- }
2451
- }
2452
- else {
2453
- itemBody += checkbox + ' ';
2454
- }
2455
- }
2456
- itemBody += this.parser.parse(item.tokens, loose);
2457
- body += this.listitem({
2458
- type: 'list_item',
2459
- raw: itemBody,
2460
- text: itemBody,
2461
- task,
2462
- checked: !!checked,
2463
- loose,
2464
- tokens: item.tokens
2465
- });
2466
- }
2467
- return func.call(this, body, ordered, start);
2468
- };
2469
- case 'html':
2470
- return function (token) {
2471
- if (!token.type || token.type !== prop) {
2472
- // @ts-ignore
2473
- // eslint-disable-next-line prefer-rest-params
2474
- return func.apply(this, arguments);
2475
- }
2476
- return func.call(this, token.text, token.block);
2477
- };
2478
- case 'paragraph':
2479
- return function (token) {
2480
- if (!token.type || token.type !== prop) {
2481
- // @ts-ignore
2482
- // eslint-disable-next-line prefer-rest-params
2483
- return func.apply(this, arguments);
2484
- }
2485
- return func.call(this, this.parser.parseInline(token.tokens));
2486
- };
2487
- case 'escape':
2488
- return function (token) {
2489
- if (!token.type || token.type !== prop) {
2490
- // @ts-ignore
2491
- // eslint-disable-next-line prefer-rest-params
2492
- return func.apply(this, arguments);
2493
- }
2494
- return func.call(this, token.text);
2495
- };
2496
- case 'link':
2497
- return function (token) {
2498
- if (!token.type || token.type !== prop) {
2499
- // @ts-ignore
2500
- // eslint-disable-next-line prefer-rest-params
2501
- return func.apply(this, arguments);
2502
- }
2503
- return func.call(this, token.href, token.title, this.parser.parseInline(token.tokens));
2504
- };
2505
- case 'image':
2506
- return function (token) {
2507
- if (!token.type || token.type !== prop) {
2508
- // @ts-ignore
2509
- // eslint-disable-next-line prefer-rest-params
2510
- return func.apply(this, arguments);
2511
- }
2512
- return func.call(this, token.href, token.title, token.text);
2513
- };
2514
- case 'strong':
2515
- return function (token) {
2516
- if (!token.type || token.type !== prop) {
2517
- // @ts-ignore
2518
- // eslint-disable-next-line prefer-rest-params
2519
- return func.apply(this, arguments);
2520
- }
2521
- return func.call(this, this.parser.parseInline(token.tokens));
2522
- };
2523
- case 'em':
2524
- return function (token) {
2525
- if (!token.type || token.type !== prop) {
2526
- // @ts-ignore
2527
- // eslint-disable-next-line prefer-rest-params
2528
- return func.apply(this, arguments);
2529
- }
2530
- return func.call(this, this.parser.parseInline(token.tokens));
2531
- };
2532
- case 'codespan':
2533
- return function (token) {
2534
- if (!token.type || token.type !== prop) {
2535
- // @ts-ignore
2536
- // eslint-disable-next-line prefer-rest-params
2537
- return func.apply(this, arguments);
2538
- }
2539
- return func.call(this, token.text);
2540
- };
2541
- case 'del':
2542
- return function (token) {
2543
- if (!token.type || token.type !== prop) {
2544
- // @ts-ignore
2545
- // eslint-disable-next-line prefer-rest-params
2546
- return func.apply(this, arguments);
2547
- }
2548
- return func.call(this, this.parser.parseInline(token.tokens));
2549
- };
2550
- case 'text':
2551
- return function (token) {
2552
- if (!token.type || token.type !== prop) {
2553
- // @ts-ignore
2554
- // eslint-disable-next-line prefer-rest-params
2555
- return func.apply(this, arguments);
2556
- }
2557
- return func.call(this, token.text);
2558
- };
2559
- // do nothing
2560
- }
2561
- return func;
2562
- }
2563
2335
  setOptions(opt) {
2564
2336
  this.defaults = { ...this.defaults, ...opt };
2565
2337
  return this;
@@ -2570,18 +2342,16 @@ class Marked {
2570
2342
  parser(tokens, options) {
2571
2343
  return _Parser.parse(tokens, options ?? this.defaults);
2572
2344
  }
2573
- #parseMarkdown(lexer, parser) {
2574
- return (src, options) => {
2345
+ parseMarkdown(lexer, parser) {
2346
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2347
+ const parse = (src, options) => {
2575
2348
  const origOpt = { ...options };
2576
2349
  const opt = { ...this.defaults, ...origOpt };
2577
- // Show warning if an extension set async to true but the parse was called with async: false
2350
+ const throwError = this.onError(!!opt.silent, !!opt.async);
2351
+ // throw error if an extension set async to true but parse was called with async: false
2578
2352
  if (this.defaults.async === true && origOpt.async === false) {
2579
- if (!opt.silent) {
2580
- console.warn('marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored.');
2581
- }
2582
- opt.async = true;
2353
+ return throwError(new Error('marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.'));
2583
2354
  }
2584
- const throwError = this.#onError(!!opt.silent, !!opt.async);
2585
2355
  // throw error in case of non string input
2586
2356
  if (typeof src === 'undefined' || src === null) {
2587
2357
  return throwError(new Error('marked(): input parameter is undefined or null'));
@@ -2623,8 +2393,9 @@ class Marked {
2623
2393
  return throwError(e);
2624
2394
  }
2625
2395
  };
2396
+ return parse;
2626
2397
  }
2627
- #onError(silent, async) {
2398
+ onError(silent, async) {
2628
2399
  return (e) => {
2629
2400
  e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2630
2401
  if (silent) {