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.umd.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
|
*/
|
|
@@ -65,21 +65,6 @@
|
|
|
65
65
|
}
|
|
66
66
|
return html;
|
|
67
67
|
}
|
|
68
|
-
const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
|
69
|
-
function unescape(html) {
|
|
70
|
-
// explicitly match decimal, hex, and named HTML entities
|
|
71
|
-
return html.replace(unescapeTest, (_, n) => {
|
|
72
|
-
n = n.toLowerCase();
|
|
73
|
-
if (n === 'colon')
|
|
74
|
-
return ':';
|
|
75
|
-
if (n.charAt(0) === '#') {
|
|
76
|
-
return n.charAt(1) === 'x'
|
|
77
|
-
? String.fromCharCode(parseInt(n.substring(2), 16))
|
|
78
|
-
: String.fromCharCode(+n.substring(1));
|
|
79
|
-
}
|
|
80
|
-
return '';
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
68
|
const caret = /(^|[^\[])\^/g;
|
|
84
69
|
function edit(regex, opt) {
|
|
85
70
|
let source = typeof regex === 'string' ? regex : regex.source;
|
|
@@ -2128,8 +2113,8 @@
|
|
|
2128
2113
|
class Marked {
|
|
2129
2114
|
defaults = _getDefaults();
|
|
2130
2115
|
options = this.setOptions;
|
|
2131
|
-
parse = this
|
|
2132
|
-
parseInline = this
|
|
2116
|
+
parse = this.parseMarkdown(_Lexer.lex, _Parser.parse);
|
|
2117
|
+
parseInline = this.parseMarkdown(_Lexer.lexInline, _Parser.parseInline);
|
|
2133
2118
|
Parser = _Parser;
|
|
2134
2119
|
Renderer = _Renderer;
|
|
2135
2120
|
TextRenderer = _TextRenderer;
|
|
@@ -2257,11 +2242,7 @@
|
|
|
2257
2242
|
continue;
|
|
2258
2243
|
}
|
|
2259
2244
|
const rendererProp = prop;
|
|
2260
|
-
|
|
2261
|
-
if (!pack.useNewRenderer) {
|
|
2262
|
-
// TODO: Remove this in next major version
|
|
2263
|
-
rendererFunc = this.#convertRendererFunction(rendererFunc, rendererProp, renderer);
|
|
2264
|
-
}
|
|
2245
|
+
const rendererFunc = pack.renderer[rendererProp];
|
|
2265
2246
|
const prevRenderer = renderer[rendererProp];
|
|
2266
2247
|
// Replace renderer with func to run extension, but fall back if false
|
|
2267
2248
|
renderer[rendererProp] = (...args) => {
|
|
@@ -2355,215 +2336,6 @@
|
|
|
2355
2336
|
});
|
|
2356
2337
|
return this;
|
|
2357
2338
|
}
|
|
2358
|
-
// TODO: Remove this in next major release
|
|
2359
|
-
#convertRendererFunction(func, prop, renderer) {
|
|
2360
|
-
switch (prop) {
|
|
2361
|
-
case 'heading':
|
|
2362
|
-
return function (token) {
|
|
2363
|
-
if (!token.type || token.type !== prop) {
|
|
2364
|
-
// @ts-ignore
|
|
2365
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2366
|
-
return func.apply(this, arguments);
|
|
2367
|
-
}
|
|
2368
|
-
return func.call(this, renderer.parser.parseInline(token.tokens), token.depth, unescape(renderer.parser.parseInline(token.tokens, renderer.parser.textRenderer)));
|
|
2369
|
-
};
|
|
2370
|
-
case 'code':
|
|
2371
|
-
return function (token) {
|
|
2372
|
-
if (!token.type || token.type !== prop) {
|
|
2373
|
-
// @ts-ignore
|
|
2374
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2375
|
-
return func.apply(this, arguments);
|
|
2376
|
-
}
|
|
2377
|
-
return func.call(this, token.text, token.lang, !!token.escaped);
|
|
2378
|
-
};
|
|
2379
|
-
case 'table':
|
|
2380
|
-
return function (token) {
|
|
2381
|
-
if (!token.type || token.type !== prop) {
|
|
2382
|
-
// @ts-ignore
|
|
2383
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2384
|
-
return func.apply(this, arguments);
|
|
2385
|
-
}
|
|
2386
|
-
let header = '';
|
|
2387
|
-
// header
|
|
2388
|
-
let cell = '';
|
|
2389
|
-
for (let j = 0; j < token.header.length; j++) {
|
|
2390
|
-
cell += this.tablecell({
|
|
2391
|
-
text: token.header[j].text,
|
|
2392
|
-
tokens: token.header[j].tokens,
|
|
2393
|
-
header: true,
|
|
2394
|
-
align: token.align[j],
|
|
2395
|
-
});
|
|
2396
|
-
}
|
|
2397
|
-
header += this.tablerow({ text: cell });
|
|
2398
|
-
let body = '';
|
|
2399
|
-
for (let j = 0; j < token.rows.length; j++) {
|
|
2400
|
-
const row = token.rows[j];
|
|
2401
|
-
cell = '';
|
|
2402
|
-
for (let k = 0; k < row.length; k++) {
|
|
2403
|
-
cell += this.tablecell({
|
|
2404
|
-
text: row[k].text,
|
|
2405
|
-
tokens: row[k].tokens,
|
|
2406
|
-
header: false,
|
|
2407
|
-
align: token.align[k],
|
|
2408
|
-
});
|
|
2409
|
-
}
|
|
2410
|
-
body += this.tablerow({ text: cell });
|
|
2411
|
-
}
|
|
2412
|
-
return func.call(this, header, body);
|
|
2413
|
-
};
|
|
2414
|
-
case 'blockquote':
|
|
2415
|
-
return function (token) {
|
|
2416
|
-
if (!token.type || token.type !== prop) {
|
|
2417
|
-
// @ts-ignore
|
|
2418
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2419
|
-
return func.apply(this, arguments);
|
|
2420
|
-
}
|
|
2421
|
-
const body = this.parser.parse(token.tokens);
|
|
2422
|
-
return func.call(this, body);
|
|
2423
|
-
};
|
|
2424
|
-
case 'list':
|
|
2425
|
-
return function (token) {
|
|
2426
|
-
if (!token.type || token.type !== prop) {
|
|
2427
|
-
// @ts-ignore
|
|
2428
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2429
|
-
return func.apply(this, arguments);
|
|
2430
|
-
}
|
|
2431
|
-
const ordered = token.ordered;
|
|
2432
|
-
const start = token.start;
|
|
2433
|
-
const loose = token.loose;
|
|
2434
|
-
let body = '';
|
|
2435
|
-
for (let j = 0; j < token.items.length; j++) {
|
|
2436
|
-
const item = token.items[j];
|
|
2437
|
-
const checked = item.checked;
|
|
2438
|
-
const task = item.task;
|
|
2439
|
-
let itemBody = '';
|
|
2440
|
-
if (item.task) {
|
|
2441
|
-
const checkbox = this.checkbox({ checked: !!checked });
|
|
2442
|
-
if (loose) {
|
|
2443
|
-
if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
|
|
2444
|
-
item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
|
|
2445
|
-
if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
|
|
2446
|
-
item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
|
|
2447
|
-
}
|
|
2448
|
-
}
|
|
2449
|
-
else {
|
|
2450
|
-
item.tokens.unshift({
|
|
2451
|
-
type: 'text',
|
|
2452
|
-
text: checkbox + ' ',
|
|
2453
|
-
});
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
else {
|
|
2457
|
-
itemBody += checkbox + ' ';
|
|
2458
|
-
}
|
|
2459
|
-
}
|
|
2460
|
-
itemBody += this.parser.parse(item.tokens, loose);
|
|
2461
|
-
body += this.listitem({
|
|
2462
|
-
type: 'list_item',
|
|
2463
|
-
raw: itemBody,
|
|
2464
|
-
text: itemBody,
|
|
2465
|
-
task,
|
|
2466
|
-
checked: !!checked,
|
|
2467
|
-
loose,
|
|
2468
|
-
tokens: item.tokens,
|
|
2469
|
-
});
|
|
2470
|
-
}
|
|
2471
|
-
return func.call(this, body, ordered, start);
|
|
2472
|
-
};
|
|
2473
|
-
case 'html':
|
|
2474
|
-
return function (token) {
|
|
2475
|
-
if (!token.type || token.type !== prop) {
|
|
2476
|
-
// @ts-ignore
|
|
2477
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2478
|
-
return func.apply(this, arguments);
|
|
2479
|
-
}
|
|
2480
|
-
return func.call(this, token.text, token.block);
|
|
2481
|
-
};
|
|
2482
|
-
case 'paragraph':
|
|
2483
|
-
return function (token) {
|
|
2484
|
-
if (!token.type || token.type !== prop) {
|
|
2485
|
-
// @ts-ignore
|
|
2486
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2487
|
-
return func.apply(this, arguments);
|
|
2488
|
-
}
|
|
2489
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2490
|
-
};
|
|
2491
|
-
case 'escape':
|
|
2492
|
-
return function (token) {
|
|
2493
|
-
if (!token.type || token.type !== prop) {
|
|
2494
|
-
// @ts-ignore
|
|
2495
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2496
|
-
return func.apply(this, arguments);
|
|
2497
|
-
}
|
|
2498
|
-
return func.call(this, token.text);
|
|
2499
|
-
};
|
|
2500
|
-
case 'link':
|
|
2501
|
-
return function (token) {
|
|
2502
|
-
if (!token.type || token.type !== prop) {
|
|
2503
|
-
// @ts-ignore
|
|
2504
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2505
|
-
return func.apply(this, arguments);
|
|
2506
|
-
}
|
|
2507
|
-
return func.call(this, token.href, token.title, this.parser.parseInline(token.tokens));
|
|
2508
|
-
};
|
|
2509
|
-
case 'image':
|
|
2510
|
-
return function (token) {
|
|
2511
|
-
if (!token.type || token.type !== prop) {
|
|
2512
|
-
// @ts-ignore
|
|
2513
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2514
|
-
return func.apply(this, arguments);
|
|
2515
|
-
}
|
|
2516
|
-
return func.call(this, token.href, token.title, token.text);
|
|
2517
|
-
};
|
|
2518
|
-
case 'strong':
|
|
2519
|
-
return function (token) {
|
|
2520
|
-
if (!token.type || token.type !== prop) {
|
|
2521
|
-
// @ts-ignore
|
|
2522
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2523
|
-
return func.apply(this, arguments);
|
|
2524
|
-
}
|
|
2525
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2526
|
-
};
|
|
2527
|
-
case 'em':
|
|
2528
|
-
return function (token) {
|
|
2529
|
-
if (!token.type || token.type !== prop) {
|
|
2530
|
-
// @ts-ignore
|
|
2531
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2532
|
-
return func.apply(this, arguments);
|
|
2533
|
-
}
|
|
2534
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2535
|
-
};
|
|
2536
|
-
case 'codespan':
|
|
2537
|
-
return function (token) {
|
|
2538
|
-
if (!token.type || token.type !== prop) {
|
|
2539
|
-
// @ts-ignore
|
|
2540
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2541
|
-
return func.apply(this, arguments);
|
|
2542
|
-
}
|
|
2543
|
-
return func.call(this, token.text);
|
|
2544
|
-
};
|
|
2545
|
-
case 'del':
|
|
2546
|
-
return function (token) {
|
|
2547
|
-
if (!token.type || token.type !== prop) {
|
|
2548
|
-
// @ts-ignore
|
|
2549
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2550
|
-
return func.apply(this, arguments);
|
|
2551
|
-
}
|
|
2552
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2553
|
-
};
|
|
2554
|
-
case 'text':
|
|
2555
|
-
return function (token) {
|
|
2556
|
-
if (!token.type || token.type !== prop) {
|
|
2557
|
-
// @ts-ignore
|
|
2558
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2559
|
-
return func.apply(this, arguments);
|
|
2560
|
-
}
|
|
2561
|
-
return func.call(this, token.text);
|
|
2562
|
-
};
|
|
2563
|
-
// do nothing
|
|
2564
|
-
}
|
|
2565
|
-
return func;
|
|
2566
|
-
}
|
|
2567
2339
|
setOptions(opt) {
|
|
2568
2340
|
this.defaults = { ...this.defaults, ...opt };
|
|
2569
2341
|
return this;
|
|
@@ -2574,18 +2346,16 @@
|
|
|
2574
2346
|
parser(tokens, options) {
|
|
2575
2347
|
return _Parser.parse(tokens, options ?? this.defaults);
|
|
2576
2348
|
}
|
|
2577
|
-
|
|
2578
|
-
|
|
2349
|
+
parseMarkdown(lexer, parser) {
|
|
2350
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2351
|
+
const parse = (src, options) => {
|
|
2579
2352
|
const origOpt = { ...options };
|
|
2580
2353
|
const opt = { ...this.defaults, ...origOpt };
|
|
2581
|
-
|
|
2354
|
+
const throwError = this.onError(!!opt.silent, !!opt.async);
|
|
2355
|
+
// throw error if an extension set async to true but parse was called with async: false
|
|
2582
2356
|
if (this.defaults.async === true && origOpt.async === false) {
|
|
2583
|
-
|
|
2584
|
-
console.warn('marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored.');
|
|
2585
|
-
}
|
|
2586
|
-
opt.async = true;
|
|
2357
|
+
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.'));
|
|
2587
2358
|
}
|
|
2588
|
-
const throwError = this.#onError(!!opt.silent, !!opt.async);
|
|
2589
2359
|
// throw error in case of non string input
|
|
2590
2360
|
if (typeof src === 'undefined' || src === null) {
|
|
2591
2361
|
return throwError(new Error('marked(): input parameter is undefined or null'));
|
|
@@ -2627,8 +2397,9 @@
|
|
|
2627
2397
|
return throwError(e);
|
|
2628
2398
|
}
|
|
2629
2399
|
};
|
|
2400
|
+
return parse;
|
|
2630
2401
|
}
|
|
2631
|
-
|
|
2402
|
+
onError(silent, async) {
|
|
2632
2403
|
return (e) => {
|
|
2633
2404
|
e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
|
2634
2405
|
if (silent) {
|