marked 7.0.3 → 7.0.5
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 +140 -106
- package/lib/marked.cjs.map +1 -1
- package/lib/marked.d.ts +32 -31
- package/lib/marked.esm.js +140 -106
- package/lib/marked.esm.js.map +1 -1
- package/lib/marked.umd.js +140 -106
- package/lib/marked.umd.js.map +1 -1
- package/marked.min.js +3 -3
- package/package.json +6 -6
package/lib/marked.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* marked v7.0.
|
|
2
|
+
* marked v7.0.5 - a markdown parser
|
|
3
3
|
* Copyright (c) 2011-2023, Christopher Jeffrey. (MIT Licensed)
|
|
4
4
|
* https://github.com/markedjs/marked
|
|
5
5
|
*/
|
|
@@ -168,7 +168,8 @@ function splitCells(tableRow, count) {
|
|
|
168
168
|
// ensure that every cell-delimiting pipe has a space
|
|
169
169
|
// before it to distinguish it from an escaped pipe
|
|
170
170
|
const row = tableRow.replace(/\|/g, (match, offset, str) => {
|
|
171
|
-
let escaped = false
|
|
171
|
+
let escaped = false;
|
|
172
|
+
let curr = offset;
|
|
172
173
|
while (--curr >= 0 && str[curr] === '\\')
|
|
173
174
|
escaped = !escaped;
|
|
174
175
|
if (escaped) {
|
|
@@ -238,9 +239,8 @@ function findClosingBracket(str, b) {
|
|
|
238
239
|
if (str.indexOf(b[1]) === -1) {
|
|
239
240
|
return -1;
|
|
240
241
|
}
|
|
241
|
-
|
|
242
|
-
let
|
|
243
|
-
for (; i < l; i++) {
|
|
242
|
+
let level = 0;
|
|
243
|
+
for (let i = 0; i < str.length; i++) {
|
|
244
244
|
if (str[i] === '\\') {
|
|
245
245
|
i++;
|
|
246
246
|
}
|
|
@@ -337,6 +337,7 @@ function indentCodeCompensation(raw, text) {
|
|
|
337
337
|
*/
|
|
338
338
|
class _Tokenizer {
|
|
339
339
|
options;
|
|
340
|
+
// TODO: Fix this rules type
|
|
340
341
|
rules;
|
|
341
342
|
lexer;
|
|
342
343
|
constructor(options) {
|
|
@@ -430,7 +431,6 @@ class _Tokenizer {
|
|
|
430
431
|
list(src) {
|
|
431
432
|
let cap = this.rules.block.list.exec(src);
|
|
432
433
|
if (cap) {
|
|
433
|
-
let raw, istask, ischecked, indent, i, blankLine, endsWithBlankLine, line, nextLine, rawLine, itemContents, endEarly;
|
|
434
434
|
let bull = cap[1].trim();
|
|
435
435
|
const isordered = bull.length > 1;
|
|
436
436
|
const list = {
|
|
@@ -447,9 +447,12 @@ class _Tokenizer {
|
|
|
447
447
|
}
|
|
448
448
|
// Get next list item
|
|
449
449
|
const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);
|
|
450
|
+
let raw = '';
|
|
451
|
+
let itemContents = '';
|
|
452
|
+
let endsWithBlankLine = false;
|
|
450
453
|
// Check if current bullet point can start a new List Item
|
|
451
454
|
while (src) {
|
|
452
|
-
endEarly = false;
|
|
455
|
+
let endEarly = false;
|
|
453
456
|
if (!(cap = itemRegex.exec(src))) {
|
|
454
457
|
break;
|
|
455
458
|
}
|
|
@@ -458,8 +461,9 @@ class _Tokenizer {
|
|
|
458
461
|
}
|
|
459
462
|
raw = cap[0];
|
|
460
463
|
src = src.substring(raw.length);
|
|
461
|
-
line = cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(3 * t.length));
|
|
462
|
-
nextLine = src.split('\n', 1)[0];
|
|
464
|
+
let line = cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(3 * t.length));
|
|
465
|
+
let nextLine = src.split('\n', 1)[0];
|
|
466
|
+
let indent = 0;
|
|
463
467
|
if (this.options.pedantic) {
|
|
464
468
|
indent = 2;
|
|
465
469
|
itemContents = line.trimLeft();
|
|
@@ -470,7 +474,7 @@ class _Tokenizer {
|
|
|
470
474
|
itemContents = line.slice(indent);
|
|
471
475
|
indent += cap[1].length;
|
|
472
476
|
}
|
|
473
|
-
blankLine = false;
|
|
477
|
+
let blankLine = false;
|
|
474
478
|
if (!line && /^ *$/.test(nextLine)) { // Items begin with at most one blank line
|
|
475
479
|
raw += nextLine + '\n';
|
|
476
480
|
src = src.substring(nextLine.length + 1);
|
|
@@ -483,7 +487,7 @@ class _Tokenizer {
|
|
|
483
487
|
const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
|
|
484
488
|
// Check if following lines should be included in List Item
|
|
485
489
|
while (src) {
|
|
486
|
-
rawLine = src.split('\n', 1)[0];
|
|
490
|
+
const rawLine = src.split('\n', 1)[0];
|
|
487
491
|
nextLine = rawLine;
|
|
488
492
|
// Re-align to follow commonmark nesting rules
|
|
489
493
|
if (this.options.pedantic) {
|
|
@@ -545,6 +549,8 @@ class _Tokenizer {
|
|
|
545
549
|
endsWithBlankLine = true;
|
|
546
550
|
}
|
|
547
551
|
}
|
|
552
|
+
let istask = null;
|
|
553
|
+
let ischecked;
|
|
548
554
|
// Check for task list items
|
|
549
555
|
if (this.options.gfm) {
|
|
550
556
|
istask = /^\[[ xX]\] /.exec(itemContents);
|
|
@@ -559,7 +565,8 @@ class _Tokenizer {
|
|
|
559
565
|
task: !!istask,
|
|
560
566
|
checked: ischecked,
|
|
561
567
|
loose: false,
|
|
562
|
-
text: itemContents
|
|
568
|
+
text: itemContents,
|
|
569
|
+
tokens: []
|
|
563
570
|
});
|
|
564
571
|
list.raw += raw;
|
|
565
572
|
}
|
|
@@ -567,9 +574,8 @@ class _Tokenizer {
|
|
|
567
574
|
list.items[list.items.length - 1].raw = raw.trimRight();
|
|
568
575
|
list.items[list.items.length - 1].text = itemContents.trimRight();
|
|
569
576
|
list.raw = list.raw.trimRight();
|
|
570
|
-
const l = list.items.length;
|
|
571
577
|
// Item child tokens handled here at end because we needed to have the final item to trim it first
|
|
572
|
-
for (i = 0; i <
|
|
578
|
+
for (let i = 0; i < list.items.length; i++) {
|
|
573
579
|
this.lexer.state.top = false;
|
|
574
580
|
list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
|
|
575
581
|
if (!list.loose) {
|
|
@@ -581,7 +587,7 @@ class _Tokenizer {
|
|
|
581
587
|
}
|
|
582
588
|
// Set all items to loose if list is loose
|
|
583
589
|
if (list.loose) {
|
|
584
|
-
for (i = 0; i <
|
|
590
|
+
for (let i = 0; i < list.items.length; i++) {
|
|
585
591
|
list.items[i].loose = true;
|
|
586
592
|
}
|
|
587
593
|
}
|
|
@@ -631,7 +637,7 @@ class _Tokenizer {
|
|
|
631
637
|
type: 'table',
|
|
632
638
|
raw: cap[0],
|
|
633
639
|
header: splitCells(cap[1]).map(c => {
|
|
634
|
-
return { text: c };
|
|
640
|
+
return { text: c, tokens: [] };
|
|
635
641
|
}),
|
|
636
642
|
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
|
637
643
|
rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : []
|
|
@@ -640,23 +646,26 @@ class _Tokenizer {
|
|
|
640
646
|
let l = item.align.length;
|
|
641
647
|
let i, j, k, row;
|
|
642
648
|
for (i = 0; i < l; i++) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
649
|
+
const align = item.align[i];
|
|
650
|
+
if (align) {
|
|
651
|
+
if (/^ *-+: *$/.test(align)) {
|
|
652
|
+
item.align[i] = 'right';
|
|
653
|
+
}
|
|
654
|
+
else if (/^ *:-+: *$/.test(align)) {
|
|
655
|
+
item.align[i] = 'center';
|
|
656
|
+
}
|
|
657
|
+
else if (/^ *:-+ *$/.test(align)) {
|
|
658
|
+
item.align[i] = 'left';
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
item.align[i] = null;
|
|
662
|
+
}
|
|
654
663
|
}
|
|
655
664
|
}
|
|
656
665
|
l = item.rows.length;
|
|
657
666
|
for (i = 0; i < l; i++) {
|
|
658
667
|
item.rows[i] = splitCells(item.rows[i], item.header.length).map(c => {
|
|
659
|
-
return { text: c };
|
|
668
|
+
return { text: c, tokens: [] };
|
|
660
669
|
});
|
|
661
670
|
}
|
|
662
671
|
// parse child tokens inside headers and cells
|
|
@@ -1307,13 +1316,11 @@ function smartypants(text) {
|
|
|
1307
1316
|
* mangle email addresses
|
|
1308
1317
|
*/
|
|
1309
1318
|
function mangle(text) {
|
|
1310
|
-
let out = ''
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
ch = 'x' + ch.toString(16);
|
|
1316
|
-
}
|
|
1319
|
+
let out = '';
|
|
1320
|
+
for (let i = 0; i < text.length; i++) {
|
|
1321
|
+
const ch = Math.random() > 0.5
|
|
1322
|
+
? 'x' + text.charCodeAt(i).toString(16)
|
|
1323
|
+
: text.charCodeAt(i).toString();
|
|
1317
1324
|
out += '&#' + ch + ';';
|
|
1318
1325
|
}
|
|
1319
1326
|
return out;
|
|
@@ -1759,7 +1766,7 @@ class _Renderer {
|
|
|
1759
1766
|
this.options = options || _defaults;
|
|
1760
1767
|
}
|
|
1761
1768
|
code(code, infostring, escaped) {
|
|
1762
|
-
const lang = (infostring || '').match(
|
|
1769
|
+
const lang = (infostring || '').match(/^\S*/)?.[0];
|
|
1763
1770
|
if (this.options.highlight) {
|
|
1764
1771
|
const out = this.options.highlight(code, lang);
|
|
1765
1772
|
if (out != null && out !== code) {
|
|
@@ -1798,7 +1805,8 @@ class _Renderer {
|
|
|
1798
1805
|
return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
|
|
1799
1806
|
}
|
|
1800
1807
|
list(body, ordered, start) {
|
|
1801
|
-
const type = ordered ? 'ol' : 'ul'
|
|
1808
|
+
const type = ordered ? 'ol' : 'ul';
|
|
1809
|
+
const startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
|
|
1802
1810
|
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
|
|
1803
1811
|
}
|
|
1804
1812
|
listitem(text, task, checked) {
|
|
@@ -1853,10 +1861,11 @@ class _Renderer {
|
|
|
1853
1861
|
return `<del>${text}</del>`;
|
|
1854
1862
|
}
|
|
1855
1863
|
link(href, title, text) {
|
|
1856
|
-
|
|
1857
|
-
if (
|
|
1864
|
+
const cleanHref = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
1865
|
+
if (cleanHref === null) {
|
|
1858
1866
|
return text;
|
|
1859
1867
|
}
|
|
1868
|
+
href = cleanHref;
|
|
1860
1869
|
let out = '<a href="' + href + '"';
|
|
1861
1870
|
if (title) {
|
|
1862
1871
|
out += ' title="' + title + '"';
|
|
@@ -1865,10 +1874,11 @@ class _Renderer {
|
|
|
1865
1874
|
return out;
|
|
1866
1875
|
}
|
|
1867
1876
|
image(href, title, text) {
|
|
1868
|
-
|
|
1869
|
-
if (
|
|
1877
|
+
const cleanHref = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
1878
|
+
if (cleanHref === null) {
|
|
1870
1879
|
return text;
|
|
1871
1880
|
}
|
|
1881
|
+
href = cleanHref;
|
|
1872
1882
|
let out = `<img src="${href}" alt="${text}"`;
|
|
1873
1883
|
if (title) {
|
|
1874
1884
|
out += ` title="${title}"`;
|
|
@@ -1996,14 +2006,14 @@ class _Parser {
|
|
|
1996
2006
|
* Parse Loop
|
|
1997
2007
|
*/
|
|
1998
2008
|
parse(tokens, top = true) {
|
|
1999
|
-
let out = ''
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
token = tokens[i];
|
|
2009
|
+
let out = '';
|
|
2010
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
2011
|
+
const token = tokens[i];
|
|
2003
2012
|
// Run any renderer extensions
|
|
2004
2013
|
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
|
|
2005
|
-
|
|
2006
|
-
|
|
2014
|
+
const genericToken = token;
|
|
2015
|
+
const ret = this.options.extensions.renderers[genericToken.type].call({ parser: this }, genericToken);
|
|
2016
|
+
if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(genericToken.type)) {
|
|
2007
2017
|
out += ret || '';
|
|
2008
2018
|
continue;
|
|
2009
2019
|
}
|
|
@@ -2017,30 +2027,30 @@ class _Parser {
|
|
|
2017
2027
|
continue;
|
|
2018
2028
|
}
|
|
2019
2029
|
case 'heading': {
|
|
2020
|
-
|
|
2030
|
+
const headingToken = token;
|
|
2031
|
+
out += this.renderer.heading(this.parseInline(headingToken.tokens), headingToken.depth, unescape(this.parseInline(headingToken.tokens, this.textRenderer)), this.slugger);
|
|
2021
2032
|
continue;
|
|
2022
2033
|
}
|
|
2023
2034
|
case 'code': {
|
|
2024
|
-
|
|
2035
|
+
const codeToken = token;
|
|
2036
|
+
out += this.renderer.code(codeToken.text, codeToken.lang, !!codeToken.escaped);
|
|
2025
2037
|
continue;
|
|
2026
2038
|
}
|
|
2027
2039
|
case 'table': {
|
|
2028
|
-
|
|
2040
|
+
const tableToken = token;
|
|
2041
|
+
let header = '';
|
|
2029
2042
|
// header
|
|
2030
|
-
cell = '';
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
cell += this.renderer.tablecell(this.parseInline(token.header[j].tokens), { header: true, align: token.align[j] });
|
|
2043
|
+
let cell = '';
|
|
2044
|
+
for (let j = 0; j < tableToken.header.length; j++) {
|
|
2045
|
+
cell += this.renderer.tablecell(this.parseInline(tableToken.header[j].tokens), { header: true, align: tableToken.align[j] });
|
|
2034
2046
|
}
|
|
2035
2047
|
header += this.renderer.tablerow(cell);
|
|
2036
|
-
body = '';
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
row = token.rows[j];
|
|
2048
|
+
let body = '';
|
|
2049
|
+
for (let j = 0; j < tableToken.rows.length; j++) {
|
|
2050
|
+
const row = tableToken.rows[j];
|
|
2040
2051
|
cell = '';
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
cell += this.renderer.tablecell(this.parseInline(row[k].tokens), { header: false, align: token.align[k] });
|
|
2052
|
+
for (let k = 0; k < row.length; k++) {
|
|
2053
|
+
cell += this.renderer.tablecell(this.parseInline(row[k].tokens), { header: false, align: tableToken.align[k] });
|
|
2044
2054
|
}
|
|
2045
2055
|
body += this.renderer.tablerow(cell);
|
|
2046
2056
|
}
|
|
@@ -2048,23 +2058,24 @@ class _Parser {
|
|
|
2048
2058
|
continue;
|
|
2049
2059
|
}
|
|
2050
2060
|
case 'blockquote': {
|
|
2051
|
-
|
|
2061
|
+
const blockquoteToken = token;
|
|
2062
|
+
const body = this.parse(blockquoteToken.tokens);
|
|
2052
2063
|
out += this.renderer.blockquote(body);
|
|
2053
2064
|
continue;
|
|
2054
2065
|
}
|
|
2055
2066
|
case 'list': {
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
body = '';
|
|
2061
|
-
for (j = 0; j <
|
|
2062
|
-
item =
|
|
2063
|
-
checked = item.checked;
|
|
2064
|
-
task = item.task;
|
|
2065
|
-
itemBody = '';
|
|
2067
|
+
const listToken = token;
|
|
2068
|
+
const ordered = listToken.ordered;
|
|
2069
|
+
const start = listToken.start;
|
|
2070
|
+
const loose = listToken.loose;
|
|
2071
|
+
let body = '';
|
|
2072
|
+
for (let j = 0; j < listToken.items.length; j++) {
|
|
2073
|
+
const item = listToken.items[j];
|
|
2074
|
+
const checked = item.checked;
|
|
2075
|
+
const task = item.task;
|
|
2076
|
+
let itemBody = '';
|
|
2066
2077
|
if (item.task) {
|
|
2067
|
-
checkbox = this.renderer.checkbox(!!checked);
|
|
2078
|
+
const checkbox = this.renderer.checkbox(!!checked);
|
|
2068
2079
|
if (loose) {
|
|
2069
2080
|
if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
|
|
2070
2081
|
item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
|
|
@@ -2090,18 +2101,21 @@ class _Parser {
|
|
|
2090
2101
|
continue;
|
|
2091
2102
|
}
|
|
2092
2103
|
case 'html': {
|
|
2093
|
-
|
|
2104
|
+
const htmlToken = token;
|
|
2105
|
+
out += this.renderer.html(htmlToken.text, htmlToken.block);
|
|
2094
2106
|
continue;
|
|
2095
2107
|
}
|
|
2096
2108
|
case 'paragraph': {
|
|
2097
|
-
|
|
2109
|
+
const paragraphToken = token;
|
|
2110
|
+
out += this.renderer.paragraph(this.parseInline(paragraphToken.tokens));
|
|
2098
2111
|
continue;
|
|
2099
2112
|
}
|
|
2100
2113
|
case 'text': {
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2114
|
+
let textToken = token;
|
|
2115
|
+
let body = textToken.tokens ? this.parseInline(textToken.tokens) : textToken.text;
|
|
2116
|
+
while (i + 1 < tokens.length && tokens[i + 1].type === 'text') {
|
|
2117
|
+
textToken = tokens[++i];
|
|
2118
|
+
body += '\n' + (textToken.tokens ? this.parseInline(textToken.tokens) : textToken.text);
|
|
2105
2119
|
}
|
|
2106
2120
|
out += top ? this.renderer.paragraph(body) : body;
|
|
2107
2121
|
continue;
|
|
@@ -2125,13 +2139,12 @@ class _Parser {
|
|
|
2125
2139
|
*/
|
|
2126
2140
|
parseInline(tokens, renderer) {
|
|
2127
2141
|
renderer = renderer || this.renderer;
|
|
2128
|
-
let out = ''
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
token = tokens[i];
|
|
2142
|
+
let out = '';
|
|
2143
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
2144
|
+
const token = tokens[i];
|
|
2132
2145
|
// Run any renderer extensions
|
|
2133
2146
|
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
|
|
2134
|
-
ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
|
|
2147
|
+
const ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
|
|
2135
2148
|
if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(token.type)) {
|
|
2136
2149
|
out += ret || '';
|
|
2137
2150
|
continue;
|
|
@@ -2139,31 +2152,38 @@ class _Parser {
|
|
|
2139
2152
|
}
|
|
2140
2153
|
switch (token.type) {
|
|
2141
2154
|
case 'escape': {
|
|
2142
|
-
|
|
2155
|
+
const escapeToken = token;
|
|
2156
|
+
out += renderer.text(escapeToken.text);
|
|
2143
2157
|
break;
|
|
2144
2158
|
}
|
|
2145
2159
|
case 'html': {
|
|
2146
|
-
|
|
2160
|
+
const tagToken = token;
|
|
2161
|
+
out += renderer.html(tagToken.text);
|
|
2147
2162
|
break;
|
|
2148
2163
|
}
|
|
2149
2164
|
case 'link': {
|
|
2150
|
-
|
|
2165
|
+
const linkToken = token;
|
|
2166
|
+
out += renderer.link(linkToken.href, linkToken.title, this.parseInline(linkToken.tokens, renderer));
|
|
2151
2167
|
break;
|
|
2152
2168
|
}
|
|
2153
2169
|
case 'image': {
|
|
2154
|
-
|
|
2170
|
+
const imageToken = token;
|
|
2171
|
+
out += renderer.image(imageToken.href, imageToken.title, imageToken.text);
|
|
2155
2172
|
break;
|
|
2156
2173
|
}
|
|
2157
2174
|
case 'strong': {
|
|
2158
|
-
|
|
2175
|
+
const strongToken = token;
|
|
2176
|
+
out += renderer.strong(this.parseInline(strongToken.tokens, renderer));
|
|
2159
2177
|
break;
|
|
2160
2178
|
}
|
|
2161
2179
|
case 'em': {
|
|
2162
|
-
|
|
2180
|
+
const emToken = token;
|
|
2181
|
+
out += renderer.em(this.parseInline(emToken.tokens, renderer));
|
|
2163
2182
|
break;
|
|
2164
2183
|
}
|
|
2165
2184
|
case 'codespan': {
|
|
2166
|
-
|
|
2185
|
+
const codespanToken = token;
|
|
2186
|
+
out += renderer.codespan(codespanToken.text);
|
|
2167
2187
|
break;
|
|
2168
2188
|
}
|
|
2169
2189
|
case 'br': {
|
|
@@ -2171,11 +2191,13 @@ class _Parser {
|
|
|
2171
2191
|
break;
|
|
2172
2192
|
}
|
|
2173
2193
|
case 'del': {
|
|
2174
|
-
|
|
2194
|
+
const delToken = token;
|
|
2195
|
+
out += renderer.del(this.parseInline(delToken.tokens, renderer));
|
|
2175
2196
|
break;
|
|
2176
2197
|
}
|
|
2177
2198
|
case 'text': {
|
|
2178
|
-
|
|
2199
|
+
const textToken = token;
|
|
2200
|
+
out += renderer.text(textToken.text);
|
|
2179
2201
|
break;
|
|
2180
2202
|
}
|
|
2181
2203
|
default: {
|
|
@@ -2243,10 +2265,11 @@ class Marked {
|
|
|
2243
2265
|
values = values.concat(callback.call(this, token));
|
|
2244
2266
|
switch (token.type) {
|
|
2245
2267
|
case 'table': {
|
|
2246
|
-
|
|
2268
|
+
const tableToken = token;
|
|
2269
|
+
for (const cell of tableToken.header) {
|
|
2247
2270
|
values = values.concat(this.walkTokens(cell.tokens, callback));
|
|
2248
2271
|
}
|
|
2249
|
-
for (const row of
|
|
2272
|
+
for (const row of tableToken.rows) {
|
|
2250
2273
|
for (const cell of row) {
|
|
2251
2274
|
values = values.concat(this.walkTokens(cell.tokens, callback));
|
|
2252
2275
|
}
|
|
@@ -2254,18 +2277,19 @@ class Marked {
|
|
|
2254
2277
|
break;
|
|
2255
2278
|
}
|
|
2256
2279
|
case 'list': {
|
|
2257
|
-
|
|
2280
|
+
const listToken = token;
|
|
2281
|
+
values = values.concat(this.walkTokens(listToken.items, callback));
|
|
2258
2282
|
break;
|
|
2259
2283
|
}
|
|
2260
2284
|
default: {
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
values = values.concat(this.walkTokens(
|
|
2285
|
+
const genericToken = token;
|
|
2286
|
+
if (this.defaults.extensions?.childTokens?.[genericToken.type]) {
|
|
2287
|
+
this.defaults.extensions.childTokens[genericToken.type].forEach((childTokens) => {
|
|
2288
|
+
values = values.concat(this.walkTokens(genericToken[childTokens], callback));
|
|
2265
2289
|
});
|
|
2266
2290
|
}
|
|
2267
|
-
else if (
|
|
2268
|
-
values = values.concat(this.walkTokens(
|
|
2291
|
+
else if (genericToken.tokens) {
|
|
2292
|
+
values = values.concat(this.walkTokens(genericToken.tokens, callback));
|
|
2269
2293
|
}
|
|
2270
2294
|
}
|
|
2271
2295
|
}
|
|
@@ -2305,8 +2329,9 @@ class Marked {
|
|
|
2305
2329
|
if (!ext.level || (ext.level !== 'block' && ext.level !== 'inline')) {
|
|
2306
2330
|
throw new Error("extension level must be 'block' or 'inline'");
|
|
2307
2331
|
}
|
|
2308
|
-
|
|
2309
|
-
|
|
2332
|
+
const extLevel = extensions[ext.level];
|
|
2333
|
+
if (extLevel) {
|
|
2334
|
+
extLevel.unshift(ext.tokenizer);
|
|
2310
2335
|
}
|
|
2311
2336
|
else {
|
|
2312
2337
|
extensions[ext.level] = [ext.tokenizer];
|
|
@@ -2404,9 +2429,10 @@ class Marked {
|
|
|
2404
2429
|
// ==-- Parse WalkTokens extensions --== //
|
|
2405
2430
|
if (pack.walkTokens) {
|
|
2406
2431
|
const walkTokens = this.defaults.walkTokens;
|
|
2432
|
+
const packWalktokens = pack.walkTokens;
|
|
2407
2433
|
opts.walkTokens = function (token) {
|
|
2408
2434
|
let values = [];
|
|
2409
|
-
values.push(
|
|
2435
|
+
values.push(packWalktokens.call(this, token));
|
|
2410
2436
|
if (walkTokens) {
|
|
2411
2437
|
values = values.concat(walkTokens.call(this, token));
|
|
2412
2438
|
}
|
|
@@ -2429,6 +2455,13 @@ class Marked {
|
|
|
2429
2455
|
}
|
|
2430
2456
|
const origOpt = { ...optOrCallback };
|
|
2431
2457
|
const opt = { ...this.defaults, ...origOpt };
|
|
2458
|
+
// Show warning if an extension set async to true but the parse was called with async: false
|
|
2459
|
+
if (this.defaults.async === true && origOpt.async === false) {
|
|
2460
|
+
if (!opt.silent) {
|
|
2461
|
+
console.warn('marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored.');
|
|
2462
|
+
}
|
|
2463
|
+
opt.async = true;
|
|
2464
|
+
}
|
|
2432
2465
|
const throwError = this.#onError(!!opt.silent, !!opt.async, callback);
|
|
2433
2466
|
// throw error in case of non string input
|
|
2434
2467
|
if (typeof src === 'undefined' || src === null) {
|
|
@@ -2443,6 +2476,7 @@ class Marked {
|
|
|
2443
2476
|
opt.hooks.options = opt;
|
|
2444
2477
|
}
|
|
2445
2478
|
if (callback) {
|
|
2479
|
+
const resultCallback = callback;
|
|
2446
2480
|
const highlight = opt.highlight;
|
|
2447
2481
|
let tokens;
|
|
2448
2482
|
try {
|
|
@@ -2473,7 +2507,7 @@ class Marked {
|
|
|
2473
2507
|
opt.highlight = highlight;
|
|
2474
2508
|
return err
|
|
2475
2509
|
? throwError(err)
|
|
2476
|
-
:
|
|
2510
|
+
: resultCallback(null, out);
|
|
2477
2511
|
};
|
|
2478
2512
|
if (!highlight || highlight.length < 3) {
|
|
2479
2513
|
return done();
|