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.d.cts
CHANGED
|
@@ -455,13 +455,8 @@ export interface MarkedExtension {
|
|
|
455
455
|
* The return value of the function is ignored.
|
|
456
456
|
*/
|
|
457
457
|
walkTokens?: ((token: Token) => void | Promise<void>) | undefined | null;
|
|
458
|
-
/**
|
|
459
|
-
* Use the new renderer that accepts an object instead of individual parameters.
|
|
460
|
-
* This option will be removed and default to true in the next major version.
|
|
461
|
-
*/
|
|
462
|
-
useNewRenderer?: boolean | undefined;
|
|
463
458
|
}
|
|
464
|
-
export interface MarkedOptions extends Omit<MarkedExtension, "
|
|
459
|
+
export interface MarkedOptions extends Omit<MarkedExtension, "hooks" | "renderer" | "tokenizer" | "extensions" | "walkTokens"> {
|
|
465
460
|
/**
|
|
466
461
|
* Hooks are methods that hook into some part of marked.
|
|
467
462
|
*/
|
|
@@ -590,11 +585,26 @@ declare function _getDefaults(): MarkedOptions;
|
|
|
590
585
|
declare let _defaults: MarkedOptions;
|
|
591
586
|
export type MaybePromise = void | Promise<void>;
|
|
592
587
|
export declare class Marked {
|
|
593
|
-
#private;
|
|
594
588
|
defaults: MarkedOptions;
|
|
595
589
|
options: (opt: MarkedOptions) => this;
|
|
596
|
-
parse:
|
|
597
|
-
|
|
590
|
+
parse: {
|
|
591
|
+
(src: string, options: MarkedOptions & {
|
|
592
|
+
async: true;
|
|
593
|
+
}): Promise<string>;
|
|
594
|
+
(src: string, options: MarkedOptions & {
|
|
595
|
+
async: false;
|
|
596
|
+
}): string;
|
|
597
|
+
(src: string, options?: MarkedOptions | undefined | null): string | Promise<string>;
|
|
598
|
+
};
|
|
599
|
+
parseInline: {
|
|
600
|
+
(src: string, options: MarkedOptions & {
|
|
601
|
+
async: true;
|
|
602
|
+
}): Promise<string>;
|
|
603
|
+
(src: string, options: MarkedOptions & {
|
|
604
|
+
async: false;
|
|
605
|
+
}): string;
|
|
606
|
+
(src: string, options?: MarkedOptions | undefined | null): string | Promise<string>;
|
|
607
|
+
};
|
|
598
608
|
Parser: typeof _Parser;
|
|
599
609
|
Renderer: typeof _Renderer;
|
|
600
610
|
TextRenderer: typeof _TextRenderer;
|
|
@@ -610,6 +620,8 @@ export declare class Marked {
|
|
|
610
620
|
setOptions(opt: MarkedOptions): this;
|
|
611
621
|
lexer(src: string, options?: MarkedOptions): TokensList;
|
|
612
622
|
parser(tokens: Token[], options?: MarkedOptions): string;
|
|
623
|
+
private parseMarkdown;
|
|
624
|
+
private onError;
|
|
613
625
|
}
|
|
614
626
|
/**
|
|
615
627
|
* Compiles markdown to HTML asynchronously.
|
|
@@ -628,7 +640,13 @@ export declare function marked(src: string, options: MarkedOptions & {
|
|
|
628
640
|
* @param options Optional hash of options
|
|
629
641
|
* @return String of compiled HTML. Will be a Promise of string if async is set to true by any extensions.
|
|
630
642
|
*/
|
|
631
|
-
export declare function marked(src: string, options
|
|
643
|
+
export declare function marked(src: string, options: MarkedOptions & {
|
|
644
|
+
async: false;
|
|
645
|
+
}): string;
|
|
646
|
+
export declare function marked(src: string, options: MarkedOptions & {
|
|
647
|
+
async: true;
|
|
648
|
+
}): Promise<string>;
|
|
649
|
+
export declare function marked(src: string, options?: MarkedOptions | undefined | null): string | Promise<string>;
|
|
632
650
|
export declare namespace marked {
|
|
633
651
|
var options: (options: MarkedOptions) => typeof marked;
|
|
634
652
|
var setOptions: (options: MarkedOptions) => typeof marked;
|
|
@@ -636,7 +654,15 @@ export declare namespace marked {
|
|
|
636
654
|
var defaults: MarkedOptions;
|
|
637
655
|
var use: (...args: MarkedExtension[]) => typeof marked;
|
|
638
656
|
var walkTokens: (tokens: Token[] | TokensList, callback: (token: Token) => MaybePromise | MaybePromise[]) => MaybePromise[];
|
|
639
|
-
var parseInline:
|
|
657
|
+
var parseInline: {
|
|
658
|
+
(src: string, options: MarkedOptions & {
|
|
659
|
+
async: true;
|
|
660
|
+
}): Promise<string>;
|
|
661
|
+
(src: string, options: MarkedOptions & {
|
|
662
|
+
async: false;
|
|
663
|
+
}): string;
|
|
664
|
+
(src: string, options?: MarkedOptions | undefined | null): string | Promise<string>;
|
|
665
|
+
};
|
|
640
666
|
var Parser: typeof _Parser;
|
|
641
667
|
var parser: typeof _Parser.parse;
|
|
642
668
|
var Renderer: typeof _Renderer;
|
|
@@ -651,7 +677,15 @@ export declare const options: (options: MarkedOptions) => typeof marked;
|
|
|
651
677
|
export declare const setOptions: (options: MarkedOptions) => typeof marked;
|
|
652
678
|
export declare const use: (...args: MarkedExtension[]) => typeof marked;
|
|
653
679
|
export declare const walkTokens: (tokens: Token[] | TokensList, callback: (token: Token) => MaybePromise | MaybePromise[]) => MaybePromise[];
|
|
654
|
-
export declare const parseInline:
|
|
680
|
+
export declare const parseInline: {
|
|
681
|
+
(src: string, options: MarkedOptions & {
|
|
682
|
+
async: true;
|
|
683
|
+
}): Promise<string>;
|
|
684
|
+
(src: string, options: MarkedOptions & {
|
|
685
|
+
async: false;
|
|
686
|
+
}): string;
|
|
687
|
+
(src: string, options?: MarkedOptions | undefined | null): string | Promise<string>;
|
|
688
|
+
};
|
|
655
689
|
export declare const parse: typeof marked;
|
|
656
690
|
export declare const parser: typeof _Parser.parse;
|
|
657
691
|
export declare const lexer: typeof _Lexer.lex;
|
package/lib/marked.d.ts
CHANGED
|
@@ -455,13 +455,8 @@ export interface MarkedExtension {
|
|
|
455
455
|
* The return value of the function is ignored.
|
|
456
456
|
*/
|
|
457
457
|
walkTokens?: ((token: Token) => void | Promise<void>) | undefined | null;
|
|
458
|
-
/**
|
|
459
|
-
* Use the new renderer that accepts an object instead of individual parameters.
|
|
460
|
-
* This option will be removed and default to true in the next major version.
|
|
461
|
-
*/
|
|
462
|
-
useNewRenderer?: boolean | undefined;
|
|
463
458
|
}
|
|
464
|
-
export interface MarkedOptions extends Omit<MarkedExtension, "
|
|
459
|
+
export interface MarkedOptions extends Omit<MarkedExtension, "hooks" | "renderer" | "tokenizer" | "extensions" | "walkTokens"> {
|
|
465
460
|
/**
|
|
466
461
|
* Hooks are methods that hook into some part of marked.
|
|
467
462
|
*/
|
|
@@ -590,11 +585,26 @@ declare function _getDefaults(): MarkedOptions;
|
|
|
590
585
|
declare let _defaults: MarkedOptions;
|
|
591
586
|
export type MaybePromise = void | Promise<void>;
|
|
592
587
|
export declare class Marked {
|
|
593
|
-
#private;
|
|
594
588
|
defaults: MarkedOptions;
|
|
595
589
|
options: (opt: MarkedOptions) => this;
|
|
596
|
-
parse:
|
|
597
|
-
|
|
590
|
+
parse: {
|
|
591
|
+
(src: string, options: MarkedOptions & {
|
|
592
|
+
async: true;
|
|
593
|
+
}): Promise<string>;
|
|
594
|
+
(src: string, options: MarkedOptions & {
|
|
595
|
+
async: false;
|
|
596
|
+
}): string;
|
|
597
|
+
(src: string, options?: MarkedOptions | undefined | null): string | Promise<string>;
|
|
598
|
+
};
|
|
599
|
+
parseInline: {
|
|
600
|
+
(src: string, options: MarkedOptions & {
|
|
601
|
+
async: true;
|
|
602
|
+
}): Promise<string>;
|
|
603
|
+
(src: string, options: MarkedOptions & {
|
|
604
|
+
async: false;
|
|
605
|
+
}): string;
|
|
606
|
+
(src: string, options?: MarkedOptions | undefined | null): string | Promise<string>;
|
|
607
|
+
};
|
|
598
608
|
Parser: typeof _Parser;
|
|
599
609
|
Renderer: typeof _Renderer;
|
|
600
610
|
TextRenderer: typeof _TextRenderer;
|
|
@@ -610,6 +620,8 @@ export declare class Marked {
|
|
|
610
620
|
setOptions(opt: MarkedOptions): this;
|
|
611
621
|
lexer(src: string, options?: MarkedOptions): TokensList;
|
|
612
622
|
parser(tokens: Token[], options?: MarkedOptions): string;
|
|
623
|
+
private parseMarkdown;
|
|
624
|
+
private onError;
|
|
613
625
|
}
|
|
614
626
|
/**
|
|
615
627
|
* Compiles markdown to HTML asynchronously.
|
|
@@ -628,7 +640,13 @@ export declare function marked(src: string, options: MarkedOptions & {
|
|
|
628
640
|
* @param options Optional hash of options
|
|
629
641
|
* @return String of compiled HTML. Will be a Promise of string if async is set to true by any extensions.
|
|
630
642
|
*/
|
|
631
|
-
export declare function marked(src: string, options
|
|
643
|
+
export declare function marked(src: string, options: MarkedOptions & {
|
|
644
|
+
async: false;
|
|
645
|
+
}): string;
|
|
646
|
+
export declare function marked(src: string, options: MarkedOptions & {
|
|
647
|
+
async: true;
|
|
648
|
+
}): Promise<string>;
|
|
649
|
+
export declare function marked(src: string, options?: MarkedOptions | undefined | null): string | Promise<string>;
|
|
632
650
|
export declare namespace marked {
|
|
633
651
|
var options: (options: MarkedOptions) => typeof marked;
|
|
634
652
|
var setOptions: (options: MarkedOptions) => typeof marked;
|
|
@@ -636,7 +654,15 @@ export declare namespace marked {
|
|
|
636
654
|
var defaults: MarkedOptions;
|
|
637
655
|
var use: (...args: MarkedExtension[]) => typeof marked;
|
|
638
656
|
var walkTokens: (tokens: Token[] | TokensList, callback: (token: Token) => MaybePromise | MaybePromise[]) => MaybePromise[];
|
|
639
|
-
var parseInline:
|
|
657
|
+
var parseInline: {
|
|
658
|
+
(src: string, options: MarkedOptions & {
|
|
659
|
+
async: true;
|
|
660
|
+
}): Promise<string>;
|
|
661
|
+
(src: string, options: MarkedOptions & {
|
|
662
|
+
async: false;
|
|
663
|
+
}): string;
|
|
664
|
+
(src: string, options?: MarkedOptions | undefined | null): string | Promise<string>;
|
|
665
|
+
};
|
|
640
666
|
var Parser: typeof _Parser;
|
|
641
667
|
var parser: typeof _Parser.parse;
|
|
642
668
|
var Renderer: typeof _Renderer;
|
|
@@ -651,7 +677,15 @@ export declare const options: (options: MarkedOptions) => typeof marked;
|
|
|
651
677
|
export declare const setOptions: (options: MarkedOptions) => typeof marked;
|
|
652
678
|
export declare const use: (...args: MarkedExtension[]) => typeof marked;
|
|
653
679
|
export declare const walkTokens: (tokens: Token[] | TokensList, callback: (token: Token) => MaybePromise | MaybePromise[]) => MaybePromise[];
|
|
654
|
-
export declare const parseInline:
|
|
680
|
+
export declare const parseInline: {
|
|
681
|
+
(src: string, options: MarkedOptions & {
|
|
682
|
+
async: true;
|
|
683
|
+
}): Promise<string>;
|
|
684
|
+
(src: string, options: MarkedOptions & {
|
|
685
|
+
async: false;
|
|
686
|
+
}): string;
|
|
687
|
+
(src: string, options?: MarkedOptions | undefined | null): string | Promise<string>;
|
|
688
|
+
};
|
|
655
689
|
export declare const parse: typeof marked;
|
|
656
690
|
export declare const parser: typeof _Parser.parse;
|
|
657
691
|
export declare const lexer: typeof _Lexer.lex;
|
package/lib/marked.esm.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
|
*/
|
|
@@ -59,21 +59,6 @@ function escape$1(html, encode) {
|
|
|
59
59
|
}
|
|
60
60
|
return html;
|
|
61
61
|
}
|
|
62
|
-
const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
|
63
|
-
function unescape(html) {
|
|
64
|
-
// explicitly match decimal, hex, and named HTML entities
|
|
65
|
-
return html.replace(unescapeTest, (_, n) => {
|
|
66
|
-
n = n.toLowerCase();
|
|
67
|
-
if (n === 'colon')
|
|
68
|
-
return ':';
|
|
69
|
-
if (n.charAt(0) === '#') {
|
|
70
|
-
return n.charAt(1) === 'x'
|
|
71
|
-
? String.fromCharCode(parseInt(n.substring(2), 16))
|
|
72
|
-
: String.fromCharCode(+n.substring(1));
|
|
73
|
-
}
|
|
74
|
-
return '';
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
62
|
const caret = /(^|[^\[])\^/g;
|
|
78
63
|
function edit(regex, opt) {
|
|
79
64
|
let source = typeof regex === 'string' ? regex : regex.source;
|
|
@@ -2122,8 +2107,8 @@ class _Hooks {
|
|
|
2122
2107
|
class Marked {
|
|
2123
2108
|
defaults = _getDefaults();
|
|
2124
2109
|
options = this.setOptions;
|
|
2125
|
-
parse = this
|
|
2126
|
-
parseInline = this
|
|
2110
|
+
parse = this.parseMarkdown(_Lexer.lex, _Parser.parse);
|
|
2111
|
+
parseInline = this.parseMarkdown(_Lexer.lexInline, _Parser.parseInline);
|
|
2127
2112
|
Parser = _Parser;
|
|
2128
2113
|
Renderer = _Renderer;
|
|
2129
2114
|
TextRenderer = _TextRenderer;
|
|
@@ -2251,11 +2236,7 @@ class Marked {
|
|
|
2251
2236
|
continue;
|
|
2252
2237
|
}
|
|
2253
2238
|
const rendererProp = prop;
|
|
2254
|
-
|
|
2255
|
-
if (!pack.useNewRenderer) {
|
|
2256
|
-
// TODO: Remove this in next major version
|
|
2257
|
-
rendererFunc = this.#convertRendererFunction(rendererFunc, rendererProp, renderer);
|
|
2258
|
-
}
|
|
2239
|
+
const rendererFunc = pack.renderer[rendererProp];
|
|
2259
2240
|
const prevRenderer = renderer[rendererProp];
|
|
2260
2241
|
// Replace renderer with func to run extension, but fall back if false
|
|
2261
2242
|
renderer[rendererProp] = (...args) => {
|
|
@@ -2349,215 +2330,6 @@ class Marked {
|
|
|
2349
2330
|
});
|
|
2350
2331
|
return this;
|
|
2351
2332
|
}
|
|
2352
|
-
// TODO: Remove this in next major release
|
|
2353
|
-
#convertRendererFunction(func, prop, renderer) {
|
|
2354
|
-
switch (prop) {
|
|
2355
|
-
case 'heading':
|
|
2356
|
-
return function (token) {
|
|
2357
|
-
if (!token.type || token.type !== prop) {
|
|
2358
|
-
// @ts-ignore
|
|
2359
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2360
|
-
return func.apply(this, arguments);
|
|
2361
|
-
}
|
|
2362
|
-
return func.call(this, renderer.parser.parseInline(token.tokens), token.depth, unescape(renderer.parser.parseInline(token.tokens, renderer.parser.textRenderer)));
|
|
2363
|
-
};
|
|
2364
|
-
case 'code':
|
|
2365
|
-
return function (token) {
|
|
2366
|
-
if (!token.type || token.type !== prop) {
|
|
2367
|
-
// @ts-ignore
|
|
2368
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2369
|
-
return func.apply(this, arguments);
|
|
2370
|
-
}
|
|
2371
|
-
return func.call(this, token.text, token.lang, !!token.escaped);
|
|
2372
|
-
};
|
|
2373
|
-
case 'table':
|
|
2374
|
-
return function (token) {
|
|
2375
|
-
if (!token.type || token.type !== prop) {
|
|
2376
|
-
// @ts-ignore
|
|
2377
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2378
|
-
return func.apply(this, arguments);
|
|
2379
|
-
}
|
|
2380
|
-
let header = '';
|
|
2381
|
-
// header
|
|
2382
|
-
let cell = '';
|
|
2383
|
-
for (let j = 0; j < token.header.length; j++) {
|
|
2384
|
-
cell += this.tablecell({
|
|
2385
|
-
text: token.header[j].text,
|
|
2386
|
-
tokens: token.header[j].tokens,
|
|
2387
|
-
header: true,
|
|
2388
|
-
align: token.align[j],
|
|
2389
|
-
});
|
|
2390
|
-
}
|
|
2391
|
-
header += this.tablerow({ text: cell });
|
|
2392
|
-
let body = '';
|
|
2393
|
-
for (let j = 0; j < token.rows.length; j++) {
|
|
2394
|
-
const row = token.rows[j];
|
|
2395
|
-
cell = '';
|
|
2396
|
-
for (let k = 0; k < row.length; k++) {
|
|
2397
|
-
cell += this.tablecell({
|
|
2398
|
-
text: row[k].text,
|
|
2399
|
-
tokens: row[k].tokens,
|
|
2400
|
-
header: false,
|
|
2401
|
-
align: token.align[k],
|
|
2402
|
-
});
|
|
2403
|
-
}
|
|
2404
|
-
body += this.tablerow({ text: cell });
|
|
2405
|
-
}
|
|
2406
|
-
return func.call(this, header, body);
|
|
2407
|
-
};
|
|
2408
|
-
case 'blockquote':
|
|
2409
|
-
return function (token) {
|
|
2410
|
-
if (!token.type || token.type !== prop) {
|
|
2411
|
-
// @ts-ignore
|
|
2412
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2413
|
-
return func.apply(this, arguments);
|
|
2414
|
-
}
|
|
2415
|
-
const body = this.parser.parse(token.tokens);
|
|
2416
|
-
return func.call(this, body);
|
|
2417
|
-
};
|
|
2418
|
-
case 'list':
|
|
2419
|
-
return function (token) {
|
|
2420
|
-
if (!token.type || token.type !== prop) {
|
|
2421
|
-
// @ts-ignore
|
|
2422
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2423
|
-
return func.apply(this, arguments);
|
|
2424
|
-
}
|
|
2425
|
-
const ordered = token.ordered;
|
|
2426
|
-
const start = token.start;
|
|
2427
|
-
const loose = token.loose;
|
|
2428
|
-
let body = '';
|
|
2429
|
-
for (let j = 0; j < token.items.length; j++) {
|
|
2430
|
-
const item = token.items[j];
|
|
2431
|
-
const checked = item.checked;
|
|
2432
|
-
const task = item.task;
|
|
2433
|
-
let itemBody = '';
|
|
2434
|
-
if (item.task) {
|
|
2435
|
-
const checkbox = this.checkbox({ checked: !!checked });
|
|
2436
|
-
if (loose) {
|
|
2437
|
-
if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
|
|
2438
|
-
item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
|
|
2439
|
-
if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
|
|
2440
|
-
item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
|
|
2441
|
-
}
|
|
2442
|
-
}
|
|
2443
|
-
else {
|
|
2444
|
-
item.tokens.unshift({
|
|
2445
|
-
type: 'text',
|
|
2446
|
-
text: checkbox + ' ',
|
|
2447
|
-
});
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
else {
|
|
2451
|
-
itemBody += checkbox + ' ';
|
|
2452
|
-
}
|
|
2453
|
-
}
|
|
2454
|
-
itemBody += this.parser.parse(item.tokens, loose);
|
|
2455
|
-
body += this.listitem({
|
|
2456
|
-
type: 'list_item',
|
|
2457
|
-
raw: itemBody,
|
|
2458
|
-
text: itemBody,
|
|
2459
|
-
task,
|
|
2460
|
-
checked: !!checked,
|
|
2461
|
-
loose,
|
|
2462
|
-
tokens: item.tokens,
|
|
2463
|
-
});
|
|
2464
|
-
}
|
|
2465
|
-
return func.call(this, body, ordered, start);
|
|
2466
|
-
};
|
|
2467
|
-
case 'html':
|
|
2468
|
-
return function (token) {
|
|
2469
|
-
if (!token.type || token.type !== prop) {
|
|
2470
|
-
// @ts-ignore
|
|
2471
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2472
|
-
return func.apply(this, arguments);
|
|
2473
|
-
}
|
|
2474
|
-
return func.call(this, token.text, token.block);
|
|
2475
|
-
};
|
|
2476
|
-
case 'paragraph':
|
|
2477
|
-
return function (token) {
|
|
2478
|
-
if (!token.type || token.type !== prop) {
|
|
2479
|
-
// @ts-ignore
|
|
2480
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2481
|
-
return func.apply(this, arguments);
|
|
2482
|
-
}
|
|
2483
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2484
|
-
};
|
|
2485
|
-
case 'escape':
|
|
2486
|
-
return function (token) {
|
|
2487
|
-
if (!token.type || token.type !== prop) {
|
|
2488
|
-
// @ts-ignore
|
|
2489
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2490
|
-
return func.apply(this, arguments);
|
|
2491
|
-
}
|
|
2492
|
-
return func.call(this, token.text);
|
|
2493
|
-
};
|
|
2494
|
-
case 'link':
|
|
2495
|
-
return function (token) {
|
|
2496
|
-
if (!token.type || token.type !== prop) {
|
|
2497
|
-
// @ts-ignore
|
|
2498
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2499
|
-
return func.apply(this, arguments);
|
|
2500
|
-
}
|
|
2501
|
-
return func.call(this, token.href, token.title, this.parser.parseInline(token.tokens));
|
|
2502
|
-
};
|
|
2503
|
-
case 'image':
|
|
2504
|
-
return function (token) {
|
|
2505
|
-
if (!token.type || token.type !== prop) {
|
|
2506
|
-
// @ts-ignore
|
|
2507
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2508
|
-
return func.apply(this, arguments);
|
|
2509
|
-
}
|
|
2510
|
-
return func.call(this, token.href, token.title, token.text);
|
|
2511
|
-
};
|
|
2512
|
-
case 'strong':
|
|
2513
|
-
return function (token) {
|
|
2514
|
-
if (!token.type || token.type !== prop) {
|
|
2515
|
-
// @ts-ignore
|
|
2516
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2517
|
-
return func.apply(this, arguments);
|
|
2518
|
-
}
|
|
2519
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2520
|
-
};
|
|
2521
|
-
case 'em':
|
|
2522
|
-
return function (token) {
|
|
2523
|
-
if (!token.type || token.type !== prop) {
|
|
2524
|
-
// @ts-ignore
|
|
2525
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2526
|
-
return func.apply(this, arguments);
|
|
2527
|
-
}
|
|
2528
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2529
|
-
};
|
|
2530
|
-
case 'codespan':
|
|
2531
|
-
return function (token) {
|
|
2532
|
-
if (!token.type || token.type !== prop) {
|
|
2533
|
-
// @ts-ignore
|
|
2534
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2535
|
-
return func.apply(this, arguments);
|
|
2536
|
-
}
|
|
2537
|
-
return func.call(this, token.text);
|
|
2538
|
-
};
|
|
2539
|
-
case 'del':
|
|
2540
|
-
return function (token) {
|
|
2541
|
-
if (!token.type || token.type !== prop) {
|
|
2542
|
-
// @ts-ignore
|
|
2543
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2544
|
-
return func.apply(this, arguments);
|
|
2545
|
-
}
|
|
2546
|
-
return func.call(this, this.parser.parseInline(token.tokens));
|
|
2547
|
-
};
|
|
2548
|
-
case 'text':
|
|
2549
|
-
return function (token) {
|
|
2550
|
-
if (!token.type || token.type !== prop) {
|
|
2551
|
-
// @ts-ignore
|
|
2552
|
-
// eslint-disable-next-line prefer-rest-params
|
|
2553
|
-
return func.apply(this, arguments);
|
|
2554
|
-
}
|
|
2555
|
-
return func.call(this, token.text);
|
|
2556
|
-
};
|
|
2557
|
-
// do nothing
|
|
2558
|
-
}
|
|
2559
|
-
return func;
|
|
2560
|
-
}
|
|
2561
2333
|
setOptions(opt) {
|
|
2562
2334
|
this.defaults = { ...this.defaults, ...opt };
|
|
2563
2335
|
return this;
|
|
@@ -2568,18 +2340,16 @@ class Marked {
|
|
|
2568
2340
|
parser(tokens, options) {
|
|
2569
2341
|
return _Parser.parse(tokens, options ?? this.defaults);
|
|
2570
2342
|
}
|
|
2571
|
-
|
|
2572
|
-
|
|
2343
|
+
parseMarkdown(lexer, parser) {
|
|
2344
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2345
|
+
const parse = (src, options) => {
|
|
2573
2346
|
const origOpt = { ...options };
|
|
2574
2347
|
const opt = { ...this.defaults, ...origOpt };
|
|
2575
|
-
|
|
2348
|
+
const throwError = this.onError(!!opt.silent, !!opt.async);
|
|
2349
|
+
// throw error if an extension set async to true but parse was called with async: false
|
|
2576
2350
|
if (this.defaults.async === true && origOpt.async === false) {
|
|
2577
|
-
|
|
2578
|
-
console.warn('marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored.');
|
|
2579
|
-
}
|
|
2580
|
-
opt.async = true;
|
|
2351
|
+
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.'));
|
|
2581
2352
|
}
|
|
2582
|
-
const throwError = this.#onError(!!opt.silent, !!opt.async);
|
|
2583
2353
|
// throw error in case of non string input
|
|
2584
2354
|
if (typeof src === 'undefined' || src === null) {
|
|
2585
2355
|
return throwError(new Error('marked(): input parameter is undefined or null'));
|
|
@@ -2621,8 +2391,9 @@ class Marked {
|
|
|
2621
2391
|
return throwError(e);
|
|
2622
2392
|
}
|
|
2623
2393
|
};
|
|
2394
|
+
return parse;
|
|
2624
2395
|
}
|
|
2625
|
-
|
|
2396
|
+
onError(silent, async) {
|
|
2626
2397
|
return (e) => {
|
|
2627
2398
|
e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
|
2628
2399
|
if (silent) {
|