marked 13.0.3 → 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 +12 -241
- 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 +12 -241
- package/lib/marked.esm.js.map +1 -1
- package/lib/marked.umd.js +12 -241
- package/lib/marked.umd.js.map +1 -1
- package/man/marked.1 +1 -1
- package/marked.min.js +2 -2
- package/package.json +7 -10
package/lib/marked.cjs
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
|
*/
|
|
@@ -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;
|
|
@@ -2124,8 +2109,8 @@ class _Hooks {
|
|
|
2124
2109
|
class Marked {
|
|
2125
2110
|
defaults = _getDefaults();
|
|
2126
2111
|
options = this.setOptions;
|
|
2127
|
-
parse = this
|
|
2128
|
-
parseInline = this
|
|
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,11 +2238,7 @@ class Marked {
|
|
|
2253
2238
|
continue;
|
|
2254
2239
|
}
|
|
2255
2240
|
const rendererProp = prop;
|
|
2256
|
-
|
|
2257
|
-
if (!pack.useNewRenderer) {
|
|
2258
|
-
// TODO: Remove this in next major version
|
|
2259
|
-
rendererFunc = this.#convertRendererFunction(rendererFunc, rendererProp, renderer);
|
|
2260
|
-
}
|
|
2241
|
+
const rendererFunc = pack.renderer[rendererProp];
|
|
2261
2242
|
const prevRenderer = renderer[rendererProp];
|
|
2262
2243
|
// Replace renderer with func to run extension, but fall back if false
|
|
2263
2244
|
renderer[rendererProp] = (...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
|
-
|
|
2574
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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) {
|