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/bin/main.js +3 -4
- package/lib/marked.cjs +66 -295
- package/lib/marked.cjs.map +1 -1
- package/lib/marked.d.cts +46 -12
- package/lib/marked.d.ts +46 -12
- package/lib/marked.esm.js +66 -295
- package/lib/marked.esm.js.map +1 -1
- package/lib/marked.umd.js +66 -295
- package/lib/marked.umd.js.map +1 -1
- package/man/marked.1 +1 -1
- package/marked.min.js +2 -2
- package/package.json +25 -29
package/lib/marked.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* marked
|
|
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
|
*/
|
|
@@ -23,7 +23,7 @@ function _getDefaults() {
|
|
|
23
23
|
renderer: null,
|
|
24
24
|
silent: false,
|
|
25
25
|
tokenizer: null,
|
|
26
|
-
walkTokens: null
|
|
26
|
+
walkTokens: null,
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
let _defaults = _getDefaults();
|
|
@@ -43,7 +43,7 @@ const escapeReplacements = {
|
|
|
43
43
|
'<': '<',
|
|
44
44
|
'>': '>',
|
|
45
45
|
'"': '"',
|
|
46
|
-
"'": '''
|
|
46
|
+
"'": ''',
|
|
47
47
|
};
|
|
48
48
|
const getEscapeReplacement = (ch) => escapeReplacements[ch];
|
|
49
49
|
function escape$1(html, encode) {
|
|
@@ -59,21 +59,6 @@ function escape$1(html, encode) {
|
|
|
59
59
|
}
|
|
60
60
|
return html;
|
|
61
61
|
}
|
|
62
|
-
const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
|
63
|
-
function unescape(html) {
|
|
64
|
-
// explicitly match decimal, hex, and named HTML entities
|
|
65
|
-
return html.replace(unescapeTest, (_, n) => {
|
|
66
|
-
n = n.toLowerCase();
|
|
67
|
-
if (n === 'colon')
|
|
68
|
-
return ':';
|
|
69
|
-
if (n.charAt(0) === '#') {
|
|
70
|
-
return n.charAt(1) === 'x'
|
|
71
|
-
? String.fromCharCode(parseInt(n.substring(2), 16))
|
|
72
|
-
: String.fromCharCode(+n.substring(1));
|
|
73
|
-
}
|
|
74
|
-
return '';
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
62
|
const caret = /(^|[^\[])\^/g;
|
|
78
63
|
function edit(regex, opt) {
|
|
79
64
|
let source = typeof regex === 'string' ? regex : regex.source;
|
|
@@ -87,7 +72,7 @@ function edit(regex, opt) {
|
|
|
87
72
|
},
|
|
88
73
|
getRegex: () => {
|
|
89
74
|
return new RegExp(source, opt);
|
|
90
|
-
}
|
|
75
|
+
},
|
|
91
76
|
};
|
|
92
77
|
return obj;
|
|
93
78
|
}
|
|
@@ -95,7 +80,7 @@ function cleanUrl(href) {
|
|
|
95
80
|
try {
|
|
96
81
|
href = encodeURI(href).replace(/%25/g, '%');
|
|
97
82
|
}
|
|
98
|
-
catch
|
|
83
|
+
catch {
|
|
99
84
|
return null;
|
|
100
85
|
}
|
|
101
86
|
return href;
|
|
@@ -206,7 +191,7 @@ function outputLink(cap, link, raw, lexer) {
|
|
|
206
191
|
href,
|
|
207
192
|
title,
|
|
208
193
|
text,
|
|
209
|
-
tokens: lexer.inlineTokens(text)
|
|
194
|
+
tokens: lexer.inlineTokens(text),
|
|
210
195
|
};
|
|
211
196
|
lexer.state.inLink = false;
|
|
212
197
|
return token;
|
|
@@ -216,7 +201,7 @@ function outputLink(cap, link, raw, lexer) {
|
|
|
216
201
|
raw,
|
|
217
202
|
href,
|
|
218
203
|
title,
|
|
219
|
-
text: escape$1(text)
|
|
204
|
+
text: escape$1(text),
|
|
220
205
|
};
|
|
221
206
|
}
|
|
222
207
|
function indentCodeCompensation(raw, text) {
|
|
@@ -255,7 +240,7 @@ class _Tokenizer {
|
|
|
255
240
|
if (cap && cap[0].length > 0) {
|
|
256
241
|
return {
|
|
257
242
|
type: 'space',
|
|
258
|
-
raw: cap[0]
|
|
243
|
+
raw: cap[0],
|
|
259
244
|
};
|
|
260
245
|
}
|
|
261
246
|
}
|
|
@@ -269,7 +254,7 @@ class _Tokenizer {
|
|
|
269
254
|
codeBlockStyle: 'indented',
|
|
270
255
|
text: !this.options.pedantic
|
|
271
256
|
? rtrim(text, '\n')
|
|
272
|
-
: text
|
|
257
|
+
: text,
|
|
273
258
|
};
|
|
274
259
|
}
|
|
275
260
|
}
|
|
@@ -282,7 +267,7 @@ class _Tokenizer {
|
|
|
282
267
|
type: 'code',
|
|
283
268
|
raw,
|
|
284
269
|
lang: cap[2] ? cap[2].trim().replace(this.rules.inline.anyPunctuation, '$1') : cap[2],
|
|
285
|
-
text
|
|
270
|
+
text,
|
|
286
271
|
};
|
|
287
272
|
}
|
|
288
273
|
}
|
|
@@ -306,7 +291,7 @@ class _Tokenizer {
|
|
|
306
291
|
raw: cap[0],
|
|
307
292
|
depth: cap[1].length,
|
|
308
293
|
text,
|
|
309
|
-
tokens: this.lexer.inline(text)
|
|
294
|
+
tokens: this.lexer.inline(text),
|
|
310
295
|
};
|
|
311
296
|
}
|
|
312
297
|
}
|
|
@@ -315,7 +300,7 @@ class _Tokenizer {
|
|
|
315
300
|
if (cap) {
|
|
316
301
|
return {
|
|
317
302
|
type: 'hr',
|
|
318
|
-
raw: rtrim(cap[0], '\n')
|
|
303
|
+
raw: rtrim(cap[0], '\n'),
|
|
319
304
|
};
|
|
320
305
|
}
|
|
321
306
|
}
|
|
@@ -392,7 +377,7 @@ class _Tokenizer {
|
|
|
392
377
|
type: 'blockquote',
|
|
393
378
|
raw,
|
|
394
379
|
tokens,
|
|
395
|
-
text
|
|
380
|
+
text,
|
|
396
381
|
};
|
|
397
382
|
}
|
|
398
383
|
}
|
|
@@ -407,7 +392,7 @@ class _Tokenizer {
|
|
|
407
392
|
ordered: isordered,
|
|
408
393
|
start: isordered ? +bull.slice(0, -1) : '',
|
|
409
394
|
loose: false,
|
|
410
|
-
items: []
|
|
395
|
+
items: [],
|
|
411
396
|
};
|
|
412
397
|
bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
|
|
413
398
|
if (this.options.pedantic) {
|
|
@@ -537,7 +522,7 @@ class _Tokenizer {
|
|
|
537
522
|
checked: ischecked,
|
|
538
523
|
loose: false,
|
|
539
524
|
text: itemContents,
|
|
540
|
-
tokens: []
|
|
525
|
+
tokens: [],
|
|
541
526
|
});
|
|
542
527
|
list.raw += raw;
|
|
543
528
|
}
|
|
@@ -573,7 +558,7 @@ class _Tokenizer {
|
|
|
573
558
|
block: true,
|
|
574
559
|
raw: cap[0],
|
|
575
560
|
pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
|
|
576
|
-
text: cap[0]
|
|
561
|
+
text: cap[0],
|
|
577
562
|
};
|
|
578
563
|
return token;
|
|
579
564
|
}
|
|
@@ -589,7 +574,7 @@ class _Tokenizer {
|
|
|
589
574
|
tag,
|
|
590
575
|
raw: cap[0],
|
|
591
576
|
href,
|
|
592
|
-
title
|
|
577
|
+
title,
|
|
593
578
|
};
|
|
594
579
|
}
|
|
595
580
|
}
|
|
@@ -610,7 +595,7 @@ class _Tokenizer {
|
|
|
610
595
|
raw: cap[0],
|
|
611
596
|
header: [],
|
|
612
597
|
align: [],
|
|
613
|
-
rows: []
|
|
598
|
+
rows: [],
|
|
614
599
|
};
|
|
615
600
|
if (headers.length !== aligns.length) {
|
|
616
601
|
// header and align columns must be equal, rows can be different.
|
|
@@ -635,7 +620,7 @@ class _Tokenizer {
|
|
|
635
620
|
text: headers[i],
|
|
636
621
|
tokens: this.lexer.inline(headers[i]),
|
|
637
622
|
header: true,
|
|
638
|
-
align: item.align[i]
|
|
623
|
+
align: item.align[i],
|
|
639
624
|
});
|
|
640
625
|
}
|
|
641
626
|
for (const row of rows) {
|
|
@@ -644,7 +629,7 @@ class _Tokenizer {
|
|
|
644
629
|
text: cell,
|
|
645
630
|
tokens: this.lexer.inline(cell),
|
|
646
631
|
header: false,
|
|
647
|
-
align: item.align[i]
|
|
632
|
+
align: item.align[i],
|
|
648
633
|
};
|
|
649
634
|
}));
|
|
650
635
|
}
|
|
@@ -658,7 +643,7 @@ class _Tokenizer {
|
|
|
658
643
|
raw: cap[0],
|
|
659
644
|
depth: cap[2].charAt(0) === '=' ? 1 : 2,
|
|
660
645
|
text: cap[1],
|
|
661
|
-
tokens: this.lexer.inline(cap[1])
|
|
646
|
+
tokens: this.lexer.inline(cap[1]),
|
|
662
647
|
};
|
|
663
648
|
}
|
|
664
649
|
}
|
|
@@ -672,7 +657,7 @@ class _Tokenizer {
|
|
|
672
657
|
type: 'paragraph',
|
|
673
658
|
raw: cap[0],
|
|
674
659
|
text,
|
|
675
|
-
tokens: this.lexer.inline(text)
|
|
660
|
+
tokens: this.lexer.inline(text),
|
|
676
661
|
};
|
|
677
662
|
}
|
|
678
663
|
}
|
|
@@ -683,7 +668,7 @@ class _Tokenizer {
|
|
|
683
668
|
type: 'text',
|
|
684
669
|
raw: cap[0],
|
|
685
670
|
text: cap[0],
|
|
686
|
-
tokens: this.lexer.inline(cap[0])
|
|
671
|
+
tokens: this.lexer.inline(cap[0]),
|
|
687
672
|
};
|
|
688
673
|
}
|
|
689
674
|
}
|
|
@@ -693,7 +678,7 @@ class _Tokenizer {
|
|
|
693
678
|
return {
|
|
694
679
|
type: 'escape',
|
|
695
680
|
raw: cap[0],
|
|
696
|
-
text: escape$1(cap[1])
|
|
681
|
+
text: escape$1(cap[1]),
|
|
697
682
|
};
|
|
698
683
|
}
|
|
699
684
|
}
|
|
@@ -718,7 +703,7 @@ class _Tokenizer {
|
|
|
718
703
|
inLink: this.lexer.state.inLink,
|
|
719
704
|
inRawBlock: this.lexer.state.inRawBlock,
|
|
720
705
|
block: false,
|
|
721
|
-
text: cap[0]
|
|
706
|
+
text: cap[0],
|
|
722
707
|
};
|
|
723
708
|
}
|
|
724
709
|
}
|
|
@@ -773,7 +758,7 @@ class _Tokenizer {
|
|
|
773
758
|
}
|
|
774
759
|
return outputLink(cap, {
|
|
775
760
|
href: href ? href.replace(this.rules.inline.anyPunctuation, '$1') : href,
|
|
776
|
-
title: title ? title.replace(this.rules.inline.anyPunctuation, '$1') : title
|
|
761
|
+
title: title ? title.replace(this.rules.inline.anyPunctuation, '$1') : title,
|
|
777
762
|
}, cap[0], this.lexer);
|
|
778
763
|
}
|
|
779
764
|
}
|
|
@@ -788,7 +773,7 @@ class _Tokenizer {
|
|
|
788
773
|
return {
|
|
789
774
|
type: 'text',
|
|
790
775
|
raw: text,
|
|
791
|
-
text
|
|
776
|
+
text,
|
|
792
777
|
};
|
|
793
778
|
}
|
|
794
779
|
return outputLink(cap, link, cap[0], this.lexer);
|
|
@@ -840,7 +825,7 @@ class _Tokenizer {
|
|
|
840
825
|
type: 'em',
|
|
841
826
|
raw,
|
|
842
827
|
text,
|
|
843
|
-
tokens: this.lexer.inlineTokens(text)
|
|
828
|
+
tokens: this.lexer.inlineTokens(text),
|
|
844
829
|
};
|
|
845
830
|
}
|
|
846
831
|
// Create 'strong' if smallest delimiter has even char count. **a***
|
|
@@ -849,7 +834,7 @@ class _Tokenizer {
|
|
|
849
834
|
type: 'strong',
|
|
850
835
|
raw,
|
|
851
836
|
text,
|
|
852
|
-
tokens: this.lexer.inlineTokens(text)
|
|
837
|
+
tokens: this.lexer.inlineTokens(text),
|
|
853
838
|
};
|
|
854
839
|
}
|
|
855
840
|
}
|
|
@@ -867,7 +852,7 @@ class _Tokenizer {
|
|
|
867
852
|
return {
|
|
868
853
|
type: 'codespan',
|
|
869
854
|
raw: cap[0],
|
|
870
|
-
text
|
|
855
|
+
text,
|
|
871
856
|
};
|
|
872
857
|
}
|
|
873
858
|
}
|
|
@@ -876,7 +861,7 @@ class _Tokenizer {
|
|
|
876
861
|
if (cap) {
|
|
877
862
|
return {
|
|
878
863
|
type: 'br',
|
|
879
|
-
raw: cap[0]
|
|
864
|
+
raw: cap[0],
|
|
880
865
|
};
|
|
881
866
|
}
|
|
882
867
|
}
|
|
@@ -887,7 +872,7 @@ class _Tokenizer {
|
|
|
887
872
|
type: 'del',
|
|
888
873
|
raw: cap[0],
|
|
889
874
|
text: cap[2],
|
|
890
|
-
tokens: this.lexer.inlineTokens(cap[2])
|
|
875
|
+
tokens: this.lexer.inlineTokens(cap[2]),
|
|
891
876
|
};
|
|
892
877
|
}
|
|
893
878
|
}
|
|
@@ -912,9 +897,9 @@ class _Tokenizer {
|
|
|
912
897
|
{
|
|
913
898
|
type: 'text',
|
|
914
899
|
raw: text,
|
|
915
|
-
text
|
|
916
|
-
}
|
|
917
|
-
]
|
|
900
|
+
text,
|
|
901
|
+
},
|
|
902
|
+
],
|
|
918
903
|
};
|
|
919
904
|
}
|
|
920
905
|
}
|
|
@@ -950,9 +935,9 @@ class _Tokenizer {
|
|
|
950
935
|
{
|
|
951
936
|
type: 'text',
|
|
952
937
|
raw: text,
|
|
953
|
-
text
|
|
954
|
-
}
|
|
955
|
-
]
|
|
938
|
+
text,
|
|
939
|
+
},
|
|
940
|
+
],
|
|
956
941
|
};
|
|
957
942
|
}
|
|
958
943
|
}
|
|
@@ -969,7 +954,7 @@ class _Tokenizer {
|
|
|
969
954
|
return {
|
|
970
955
|
type: 'text',
|
|
971
956
|
raw: cap[0],
|
|
972
|
-
text
|
|
957
|
+
text,
|
|
973
958
|
};
|
|
974
959
|
}
|
|
975
960
|
}
|
|
@@ -1053,7 +1038,7 @@ const blockNormal = {
|
|
|
1053
1038
|
newline,
|
|
1054
1039
|
paragraph,
|
|
1055
1040
|
table: noopTest,
|
|
1056
|
-
text: blockText
|
|
1041
|
+
text: blockText,
|
|
1057
1042
|
};
|
|
1058
1043
|
/**
|
|
1059
1044
|
* GFM Block Grammar
|
|
@@ -1083,7 +1068,7 @@ const blockGfm = {
|
|
|
1083
1068
|
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
|
|
1084
1069
|
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
|
|
1085
1070
|
.replace('tag', _tag) // pars can be interrupted by type (6) html blocks
|
|
1086
|
-
.getRegex()
|
|
1071
|
+
.getRegex(),
|
|
1087
1072
|
};
|
|
1088
1073
|
/**
|
|
1089
1074
|
* Pedantic grammar (original John Gruber's loose markdown specification)
|
|
@@ -1113,7 +1098,7 @@ const blockPedantic = {
|
|
|
1113
1098
|
.replace('|list', '')
|
|
1114
1099
|
.replace('|html', '')
|
|
1115
1100
|
.replace('|tag', '')
|
|
1116
|
-
.getRegex()
|
|
1101
|
+
.getRegex(),
|
|
1117
1102
|
};
|
|
1118
1103
|
/**
|
|
1119
1104
|
* Inline-Level Grammar
|
|
@@ -1207,7 +1192,7 @@ const inlineNormal = {
|
|
|
1207
1192
|
reflinkSearch,
|
|
1208
1193
|
tag,
|
|
1209
1194
|
text: inlineText,
|
|
1210
|
-
url: noopTest
|
|
1195
|
+
url: noopTest,
|
|
1211
1196
|
};
|
|
1212
1197
|
/**
|
|
1213
1198
|
* Pedantic Inline Grammar
|
|
@@ -1219,7 +1204,7 @@ const inlinePedantic = {
|
|
|
1219
1204
|
.getRegex(),
|
|
1220
1205
|
reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
|
|
1221
1206
|
.replace('label', _inlineLabel)
|
|
1222
|
-
.getRegex()
|
|
1207
|
+
.getRegex(),
|
|
1223
1208
|
};
|
|
1224
1209
|
/**
|
|
1225
1210
|
* GFM Inline Grammar
|
|
@@ -1232,7 +1217,7 @@ const inlineGfm = {
|
|
|
1232
1217
|
.getRegex(),
|
|
1233
1218
|
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
|
|
1234
1219
|
del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
|
|
1235
|
-
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))
|
|
1220
|
+
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/,
|
|
1236
1221
|
};
|
|
1237
1222
|
/**
|
|
1238
1223
|
* GFM + Line Breaks Inline Grammar
|
|
@@ -1243,7 +1228,7 @@ const inlineBreaks = {
|
|
|
1243
1228
|
text: edit(inlineGfm.text)
|
|
1244
1229
|
.replace('\\b_', '\\b_| {2,}\\n')
|
|
1245
1230
|
.replace(/\{2,\}/g, '*')
|
|
1246
|
-
.getRegex()
|
|
1231
|
+
.getRegex(),
|
|
1247
1232
|
};
|
|
1248
1233
|
/**
|
|
1249
1234
|
* exports
|
|
@@ -1251,13 +1236,13 @@ const inlineBreaks = {
|
|
|
1251
1236
|
const block = {
|
|
1252
1237
|
normal: blockNormal,
|
|
1253
1238
|
gfm: blockGfm,
|
|
1254
|
-
pedantic: blockPedantic
|
|
1239
|
+
pedantic: blockPedantic,
|
|
1255
1240
|
};
|
|
1256
1241
|
const inline = {
|
|
1257
1242
|
normal: inlineNormal,
|
|
1258
1243
|
gfm: inlineGfm,
|
|
1259
1244
|
breaks: inlineBreaks,
|
|
1260
|
-
pedantic: inlinePedantic
|
|
1245
|
+
pedantic: inlinePedantic,
|
|
1261
1246
|
};
|
|
1262
1247
|
|
|
1263
1248
|
/**
|
|
@@ -1282,11 +1267,11 @@ class _Lexer {
|
|
|
1282
1267
|
this.state = {
|
|
1283
1268
|
inLink: false,
|
|
1284
1269
|
inRawBlock: false,
|
|
1285
|
-
top: true
|
|
1270
|
+
top: true,
|
|
1286
1271
|
};
|
|
1287
1272
|
const rules = {
|
|
1288
1273
|
block: block.normal,
|
|
1289
|
-
inline: inline.normal
|
|
1274
|
+
inline: inline.normal,
|
|
1290
1275
|
};
|
|
1291
1276
|
if (this.options.pedantic) {
|
|
1292
1277
|
rules.block = block.pedantic;
|
|
@@ -1309,7 +1294,7 @@ class _Lexer {
|
|
|
1309
1294
|
static get rules() {
|
|
1310
1295
|
return {
|
|
1311
1296
|
block,
|
|
1312
|
-
inline
|
|
1297
|
+
inline,
|
|
1313
1298
|
};
|
|
1314
1299
|
}
|
|
1315
1300
|
/**
|
|
@@ -1441,7 +1426,7 @@ class _Lexer {
|
|
|
1441
1426
|
else if (!this.tokens.links[token.tag]) {
|
|
1442
1427
|
this.tokens.links[token.tag] = {
|
|
1443
1428
|
href: token.href,
|
|
1444
|
-
title: token.title
|
|
1429
|
+
title: token.title,
|
|
1445
1430
|
};
|
|
1446
1431
|
}
|
|
1447
1432
|
continue;
|
|
@@ -1757,7 +1742,7 @@ class _Renderer {
|
|
|
1757
1742
|
item.tokens.unshift({
|
|
1758
1743
|
type: 'text',
|
|
1759
1744
|
raw: checkbox + ' ',
|
|
1760
|
-
text: checkbox + ' '
|
|
1745
|
+
text: checkbox + ' ',
|
|
1761
1746
|
});
|
|
1762
1747
|
}
|
|
1763
1748
|
}
|
|
@@ -1993,7 +1978,7 @@ class _Parser {
|
|
|
1993
1978
|
type: 'paragraph',
|
|
1994
1979
|
raw: body,
|
|
1995
1980
|
text: body,
|
|
1996
|
-
tokens: [{ type: 'text', raw: body, text: body }]
|
|
1981
|
+
tokens: [{ type: 'text', raw: body, text: body }],
|
|
1997
1982
|
});
|
|
1998
1983
|
}
|
|
1999
1984
|
else {
|
|
@@ -2097,7 +2082,7 @@ class _Hooks {
|
|
|
2097
2082
|
static passThroughHooks = new Set([
|
|
2098
2083
|
'preprocess',
|
|
2099
2084
|
'postprocess',
|
|
2100
|
-
'processAllTokens'
|
|
2085
|
+
'processAllTokens',
|
|
2101
2086
|
]);
|
|
2102
2087
|
/**
|
|
2103
2088
|
* Process markdown before marked
|
|
@@ -2122,8 +2107,8 @@ class _Hooks {
|
|
|
2122
2107
|
class Marked {
|
|
2123
2108
|
defaults = _getDefaults();
|
|
2124
2109
|
options = this.setOptions;
|
|
2125
|
-
parse = this
|
|
2126
|
-
parseInline = this
|
|
2110
|
+
parse = this.parseMarkdown(_Lexer.lex, _Parser.parse);
|
|
2111
|
+
parseInline = this.parseMarkdown(_Lexer.lexInline, _Parser.parseInline);
|
|
2127
2112
|
Parser = _Parser;
|
|
2128
2113
|
Renderer = _Renderer;
|
|
2129
2114
|
TextRenderer = _TextRenderer;
|
|
@@ -2251,14 +2236,10 @@ class Marked {
|
|
|
2251
2236
|
continue;
|
|
2252
2237
|
}
|
|
2253
2238
|
const rendererProp = prop;
|
|
2254
|
-
|
|
2239
|
+
const rendererFunc = pack.renderer[rendererProp];
|
|
2255
2240
|
const prevRenderer = renderer[rendererProp];
|
|
2256
2241
|
// Replace renderer with func to run extension, but fall back if false
|
|
2257
2242
|
renderer[rendererProp] = (...args) => {
|
|
2258
|
-
if (!pack.useNewRenderer) {
|
|
2259
|
-
// TODO: Remove this in next major version
|
|
2260
|
-
rendererFunc = this.#convertRendererFunction(rendererFunc, rendererProp, renderer);
|
|
2261
|
-
}
|
|
2262
2243
|
let ret = rendererFunc.apply(renderer, args);
|
|
2263
2244
|
if (ret === false) {
|
|
2264
2245
|
ret = prevRenderer.apply(renderer, args);
|
|
@@ -2349,215 +2330,6 @@ class Marked {
|
|
|
2349
2330
|
});
|
|
2350
2331
|
return this;
|
|
2351
2332
|
}
|
|
2352
|
-
// TODO: Remove this in next major release
|
|
2353
|
-
#convertRendererFunction(func, prop, renderer) {
|
|
2354
|
-
switch (prop) {
|
|
2355
|
-
case 'heading':
|
|
2356
|
-
return function (token) {
|
|
2357
|
-
if (!token.type || token.type !== prop) {
|
|
2358
|
-
// @ts-ignore
|
|
2359
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2360
|
-
return func.apply(this, arguments);
|
|
2361
|
-
}
|
|
2362
|
-
return func.call(this, renderer.parser.parseInline(token.tokens), token.depth, unescape(renderer.parser.parseInline(token.tokens, renderer.parser.textRenderer)));
|
|
2363
|
-
};
|
|
2364
|
-
case 'code':
|
|
2365
|
-
return function (token) {
|
|
2366
|
-
if (!token.type || token.type !== prop) {
|
|
2367
|
-
// @ts-ignore
|
|
2368
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2369
|
-
return func.apply(this, arguments);
|
|
2370
|
-
}
|
|
2371
|
-
return func.call(this, token.text, token.lang, !!token.escaped);
|
|
2372
|
-
};
|
|
2373
|
-
case 'table':
|
|
2374
|
-
return function (token) {
|
|
2375
|
-
if (!token.type || token.type !== prop) {
|
|
2376
|
-
// @ts-ignore
|
|
2377
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2378
|
-
return func.apply(this, arguments);
|
|
2379
|
-
}
|
|
2380
|
-
let header = '';
|
|
2381
|
-
// header
|
|
2382
|
-
let cell = '';
|
|
2383
|
-
for (let j = 0; j < token.header.length; j++) {
|
|
2384
|
-
cell += this.tablecell({
|
|
2385
|
-
text: token.header[j].text,
|
|
2386
|
-
tokens: token.header[j].tokens,
|
|
2387
|
-
header: true,
|
|
2388
|
-
align: token.align[j]
|
|
2389
|
-
});
|
|
2390
|
-
}
|
|
2391
|
-
header += this.tablerow({ text: cell });
|
|
2392
|
-
let body = '';
|
|
2393
|
-
for (let j = 0; j < token.rows.length; j++) {
|
|
2394
|
-
const row = token.rows[j];
|
|
2395
|
-
cell = '';
|
|
2396
|
-
for (let k = 0; k < row.length; k++) {
|
|
2397
|
-
cell += this.tablecell({
|
|
2398
|
-
text: row[k].text,
|
|
2399
|
-
tokens: row[k].tokens,
|
|
2400
|
-
header: false,
|
|
2401
|
-
align: token.align[k]
|
|
2402
|
-
});
|
|
2403
|
-
}
|
|
2404
|
-
body += this.tablerow({ text: cell });
|
|
2405
|
-
}
|
|
2406
|
-
return func.call(this, header, body);
|
|
2407
|
-
};
|
|
2408
|
-
case 'blockquote':
|
|
2409
|
-
return function (token) {
|
|
2410
|
-
if (!token.type || token.type !== prop) {
|
|
2411
|
-
// @ts-ignore
|
|
2412
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2413
|
-
return func.apply(this, arguments);
|
|
2414
|
-
}
|
|
2415
|
-
const body = this.parser.parse(token.tokens);
|
|
2416
|
-
return func.call(this, body);
|
|
2417
|
-
};
|
|
2418
|
-
case 'list':
|
|
2419
|
-
return function (token) {
|
|
2420
|
-
if (!token.type || token.type !== prop) {
|
|
2421
|
-
// @ts-ignore
|
|
2422
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2423
|
-
return func.apply(this, arguments);
|
|
2424
|
-
}
|
|
2425
|
-
const ordered = token.ordered;
|
|
2426
|
-
const start = token.start;
|
|
2427
|
-
const loose = token.loose;
|
|
2428
|
-
let body = '';
|
|
2429
|
-
for (let j = 0; j < token.items.length; j++) {
|
|
2430
|
-
const item = token.items[j];
|
|
2431
|
-
const checked = item.checked;
|
|
2432
|
-
const task = item.task;
|
|
2433
|
-
let itemBody = '';
|
|
2434
|
-
if (item.task) {
|
|
2435
|
-
const checkbox = this.checkbox({ checked: !!checked });
|
|
2436
|
-
if (loose) {
|
|
2437
|
-
if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
|
|
2438
|
-
item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
|
|
2439
|
-
if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
|
|
2440
|
-
item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
|
|
2441
|
-
}
|
|
2442
|
-
}
|
|
2443
|
-
else {
|
|
2444
|
-
item.tokens.unshift({
|
|
2445
|
-
type: 'text',
|
|
2446
|
-
text: checkbox + ' '
|
|
2447
|
-
});
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
else {
|
|
2451
|
-
itemBody += checkbox + ' ';
|
|
2452
|
-
}
|
|
2453
|
-
}
|
|
2454
|
-
itemBody += this.parser.parse(item.tokens, loose);
|
|
2455
|
-
body += this.listitem({
|
|
2456
|
-
type: 'list_item',
|
|
2457
|
-
raw: itemBody,
|
|
2458
|
-
text: itemBody,
|
|
2459
|
-
task,
|
|
2460
|
-
checked: !!checked,
|
|
2461
|
-
loose,
|
|
2462
|
-
tokens: item.tokens
|
|
2463
|
-
});
|
|
2464
|
-
}
|
|
2465
|
-
return func.call(this, body, ordered, start);
|
|
2466
|
-
};
|
|
2467
|
-
case 'html':
|
|
2468
|
-
return function (token) {
|
|
2469
|
-
if (!token.type || token.type !== prop) {
|
|
2470
|
-
// @ts-ignore
|
|
2471
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2472
|
-
return func.apply(this, arguments);
|
|
2473
|
-
}
|
|
2474
|
-
return func.call(this, token.text, token.block);
|
|
2475
|
-
};
|
|
2476
|
-
case 'paragraph':
|
|
2477
|
-
return function (token) {
|
|
2478
|
-
if (!token.type || token.type !== prop) {
|
|
2479
|
-
// @ts-ignore
|
|
2480
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2481
|
-
return func.apply(this, arguments);
|
|
2482
|
-
}
|
|
2483
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2484
|
-
};
|
|
2485
|
-
case 'escape':
|
|
2486
|
-
return function (token) {
|
|
2487
|
-
if (!token.type || token.type !== prop) {
|
|
2488
|
-
// @ts-ignore
|
|
2489
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2490
|
-
return func.apply(this, arguments);
|
|
2491
|
-
}
|
|
2492
|
-
return func.call(this, token.text);
|
|
2493
|
-
};
|
|
2494
|
-
case 'link':
|
|
2495
|
-
return function (token) {
|
|
2496
|
-
if (!token.type || token.type !== prop) {
|
|
2497
|
-
// @ts-ignore
|
|
2498
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2499
|
-
return func.apply(this, arguments);
|
|
2500
|
-
}
|
|
2501
|
-
return func.call(this, token.href, token.title, this.parser.parseInline(token.tokens));
|
|
2502
|
-
};
|
|
2503
|
-
case 'image':
|
|
2504
|
-
return function (token) {
|
|
2505
|
-
if (!token.type || token.type !== prop) {
|
|
2506
|
-
// @ts-ignore
|
|
2507
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2508
|
-
return func.apply(this, arguments);
|
|
2509
|
-
}
|
|
2510
|
-
return func.call(this, token.href, token.title, token.text);
|
|
2511
|
-
};
|
|
2512
|
-
case 'strong':
|
|
2513
|
-
return function (token) {
|
|
2514
|
-
if (!token.type || token.type !== prop) {
|
|
2515
|
-
// @ts-ignore
|
|
2516
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2517
|
-
return func.apply(this, arguments);
|
|
2518
|
-
}
|
|
2519
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2520
|
-
};
|
|
2521
|
-
case 'em':
|
|
2522
|
-
return function (token) {
|
|
2523
|
-
if (!token.type || token.type !== prop) {
|
|
2524
|
-
// @ts-ignore
|
|
2525
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2526
|
-
return func.apply(this, arguments);
|
|
2527
|
-
}
|
|
2528
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2529
|
-
};
|
|
2530
|
-
case 'codespan':
|
|
2531
|
-
return function (token) {
|
|
2532
|
-
if (!token.type || token.type !== prop) {
|
|
2533
|
-
// @ts-ignore
|
|
2534
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2535
|
-
return func.apply(this, arguments);
|
|
2536
|
-
}
|
|
2537
|
-
return func.call(this, token.text);
|
|
2538
|
-
};
|
|
2539
|
-
case 'del':
|
|
2540
|
-
return function (token) {
|
|
2541
|
-
if (!token.type || token.type !== prop) {
|
|
2542
|
-
// @ts-ignore
|
|
2543
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2544
|
-
return func.apply(this, arguments);
|
|
2545
|
-
}
|
|
2546
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2547
|
-
};
|
|
2548
|
-
case 'text':
|
|
2549
|
-
return function (token) {
|
|
2550
|
-
if (!token.type || token.type !== prop) {
|
|
2551
|
-
// @ts-ignore
|
|
2552
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2553
|
-
return func.apply(this, arguments);
|
|
2554
|
-
}
|
|
2555
|
-
return func.call(this, token.text);
|
|
2556
|
-
};
|
|
2557
|
-
// do nothing
|
|
2558
|
-
}
|
|
2559
|
-
return func;
|
|
2560
|
-
}
|
|
2561
2333
|
setOptions(opt) {
|
|
2562
2334
|
this.defaults = { ...this.defaults, ...opt };
|
|
2563
2335
|
return this;
|
|
@@ -2568,18 +2340,16 @@ class Marked {
|
|
|
2568
2340
|
parser(tokens, options) {
|
|
2569
2341
|
return _Parser.parse(tokens, options ?? this.defaults);
|
|
2570
2342
|
}
|
|
2571
|
-
|
|
2572
|
-
|
|
2343
|
+
parseMarkdown(lexer, parser) {
|
|
2344
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2345
|
+
const parse = (src, options) => {
|
|
2573
2346
|
const origOpt = { ...options };
|
|
2574
2347
|
const opt = { ...this.defaults, ...origOpt };
|
|
2575
|
-
|
|
2348
|
+
const throwError = this.onError(!!opt.silent, !!opt.async);
|
|
2349
|
+
// throw error if an extension set async to true but parse was called with async: false
|
|
2576
2350
|
if (this.defaults.async === true && origOpt.async === false) {
|
|
2577
|
-
|
|
2578
|
-
console.warn('marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored.');
|
|
2579
|
-
}
|
|
2580
|
-
opt.async = true;
|
|
2351
|
+
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.'));
|
|
2581
2352
|
}
|
|
2582
|
-
const throwError = this.#onError(!!opt.silent, !!opt.async);
|
|
2583
2353
|
// throw error in case of non string input
|
|
2584
2354
|
if (typeof src === 'undefined' || src === null) {
|
|
2585
2355
|
return throwError(new Error('marked(): input parameter is undefined or null'));
|
|
@@ -2621,8 +2391,9 @@ class Marked {
|
|
|
2621
2391
|
return throwError(e);
|
|
2622
2392
|
}
|
|
2623
2393
|
};
|
|
2394
|
+
return parse;
|
|
2624
2395
|
}
|
|
2625
|
-
|
|
2396
|
+
onError(silent, async) {
|
|
2626
2397
|
return (e) => {
|
|
2627
2398
|
e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
|
2628
2399
|
if (silent) {
|