marked 13.0.3 → 14.1.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 +30 -243
- package/lib/marked.cjs.map +1 -1
- package/lib/marked.d.cts +58 -61
- package/lib/marked.d.ts +58 -61
- package/lib/marked.esm.js +30 -243
- package/lib/marked.esm.js.map +1 -1
- package/lib/marked.umd.js +30 -243
- package/lib/marked.umd.js.map +1 -1
- package/man/marked.1 +1 -1
- package/marked.min.js +2 -2
- package/package.json +12 -15
package/lib/marked.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* marked
|
|
2
|
+
* marked v14.1.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;
|
|
@@ -2097,6 +2082,7 @@
|
|
|
2097
2082
|
|
|
2098
2083
|
class _Hooks {
|
|
2099
2084
|
options;
|
|
2085
|
+
block;
|
|
2100
2086
|
constructor(options) {
|
|
2101
2087
|
this.options = options || exports.defaults;
|
|
2102
2088
|
}
|
|
@@ -2123,13 +2109,25 @@
|
|
|
2123
2109
|
processAllTokens(tokens) {
|
|
2124
2110
|
return tokens;
|
|
2125
2111
|
}
|
|
2112
|
+
/**
|
|
2113
|
+
* Provide function to tokenize markdown
|
|
2114
|
+
*/
|
|
2115
|
+
provideLexer() {
|
|
2116
|
+
return this.block ? _Lexer.lex : _Lexer.lexInline;
|
|
2117
|
+
}
|
|
2118
|
+
/**
|
|
2119
|
+
* Provide function to parse tokens
|
|
2120
|
+
*/
|
|
2121
|
+
provideParser() {
|
|
2122
|
+
return this.block ? _Parser.parse : _Parser.parseInline;
|
|
2123
|
+
}
|
|
2126
2124
|
}
|
|
2127
2125
|
|
|
2128
2126
|
class Marked {
|
|
2129
2127
|
defaults = _getDefaults();
|
|
2130
2128
|
options = this.setOptions;
|
|
2131
|
-
parse = this
|
|
2132
|
-
parseInline = this
|
|
2129
|
+
parse = this.parseMarkdown(true);
|
|
2130
|
+
parseInline = this.parseMarkdown(false);
|
|
2133
2131
|
Parser = _Parser;
|
|
2134
2132
|
Renderer = _Renderer;
|
|
2135
2133
|
TextRenderer = _TextRenderer;
|
|
@@ -2257,11 +2255,7 @@
|
|
|
2257
2255
|
continue;
|
|
2258
2256
|
}
|
|
2259
2257
|
const rendererProp = prop;
|
|
2260
|
-
|
|
2261
|
-
if (!pack.useNewRenderer) {
|
|
2262
|
-
// TODO: Remove this in next major version
|
|
2263
|
-
rendererFunc = this.#convertRendererFunction(rendererFunc, rendererProp, renderer);
|
|
2264
|
-
}
|
|
2258
|
+
const rendererFunc = pack.renderer[rendererProp];
|
|
2265
2259
|
const prevRenderer = renderer[rendererProp];
|
|
2266
2260
|
// Replace renderer with func to run extension, but fall back if false
|
|
2267
2261
|
renderer[rendererProp] = (...args) => {
|
|
@@ -2306,8 +2300,8 @@
|
|
|
2306
2300
|
if (!(prop in hooks)) {
|
|
2307
2301
|
throw new Error(`hook '${prop}' does not exist`);
|
|
2308
2302
|
}
|
|
2309
|
-
if (
|
|
2310
|
-
// ignore options
|
|
2303
|
+
if (['options', 'block'].includes(prop)) {
|
|
2304
|
+
// ignore options and block properties
|
|
2311
2305
|
continue;
|
|
2312
2306
|
}
|
|
2313
2307
|
const hooksProp = prop;
|
|
@@ -2355,215 +2349,6 @@
|
|
|
2355
2349
|
});
|
|
2356
2350
|
return this;
|
|
2357
2351
|
}
|
|
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
2352
|
setOptions(opt) {
|
|
2568
2353
|
this.defaults = { ...this.defaults, ...opt };
|
|
2569
2354
|
return this;
|
|
@@ -2574,18 +2359,16 @@
|
|
|
2574
2359
|
parser(tokens, options) {
|
|
2575
2360
|
return _Parser.parse(tokens, options ?? this.defaults);
|
|
2576
2361
|
}
|
|
2577
|
-
|
|
2578
|
-
|
|
2362
|
+
parseMarkdown(blockType) {
|
|
2363
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2364
|
+
const parse = (src, options) => {
|
|
2579
2365
|
const origOpt = { ...options };
|
|
2580
2366
|
const opt = { ...this.defaults, ...origOpt };
|
|
2581
|
-
|
|
2367
|
+
const throwError = this.onError(!!opt.silent, !!opt.async);
|
|
2368
|
+
// throw error if an extension set async to true but parse was called with async: false
|
|
2582
2369
|
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;
|
|
2370
|
+
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
2371
|
}
|
|
2588
|
-
const throwError = this.#onError(!!opt.silent, !!opt.async);
|
|
2589
2372
|
// throw error in case of non string input
|
|
2590
2373
|
if (typeof src === 'undefined' || src === null) {
|
|
2591
2374
|
return throwError(new Error('marked(): input parameter is undefined or null'));
|
|
@@ -2596,7 +2379,10 @@
|
|
|
2596
2379
|
}
|
|
2597
2380
|
if (opt.hooks) {
|
|
2598
2381
|
opt.hooks.options = opt;
|
|
2382
|
+
opt.hooks.block = blockType;
|
|
2599
2383
|
}
|
|
2384
|
+
const lexer = opt.hooks ? opt.hooks.provideLexer() : (blockType ? _Lexer.lex : _Lexer.lexInline);
|
|
2385
|
+
const parser = opt.hooks ? opt.hooks.provideParser() : (blockType ? _Parser.parse : _Parser.parseInline);
|
|
2600
2386
|
if (opt.async) {
|
|
2601
2387
|
return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
|
|
2602
2388
|
.then(src => lexer(src, opt))
|
|
@@ -2627,8 +2413,9 @@
|
|
|
2627
2413
|
return throwError(e);
|
|
2628
2414
|
}
|
|
2629
2415
|
};
|
|
2416
|
+
return parse;
|
|
2630
2417
|
}
|
|
2631
|
-
|
|
2418
|
+
onError(silent, async) {
|
|
2632
2419
|
return (e) => {
|
|
2633
2420
|
e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
|
2634
2421
|
if (silent) {
|