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