marked 11.0.1 → 11.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 +16 -3
- package/lib/marked.cjs.map +1 -1
- package/lib/marked.d.cts +28 -19
- package/lib/marked.d.ts +28 -19
- package/lib/marked.esm.js +16 -3
- package/lib/marked.esm.js.map +1 -1
- package/lib/marked.umd.js +16 -3
- package/lib/marked.umd.js.map +1 -1
- package/man/marked.1 +1 -1
- package/marked.min.js +2 -2
- package/package.json +6 -6
package/lib/marked.d.cts
CHANGED
|
@@ -335,6 +335,23 @@ declare class _Tokenizer {
|
|
|
335
335
|
url(src: string): Tokens.Link | undefined;
|
|
336
336
|
inlineText(src: string): Tokens.Text | undefined;
|
|
337
337
|
}
|
|
338
|
+
declare class _Hooks {
|
|
339
|
+
options: MarkedOptions;
|
|
340
|
+
constructor(options?: MarkedOptions);
|
|
341
|
+
static passThroughHooks: Set<string>;
|
|
342
|
+
/**
|
|
343
|
+
* Process markdown before marked
|
|
344
|
+
*/
|
|
345
|
+
preprocess(markdown: string): string;
|
|
346
|
+
/**
|
|
347
|
+
* Process HTML after marked is finished
|
|
348
|
+
*/
|
|
349
|
+
postprocess(html: string): string;
|
|
350
|
+
/**
|
|
351
|
+
* Process all tokens before walk tokens
|
|
352
|
+
*/
|
|
353
|
+
processAllTokens(tokens: Token[] | TokensList): Token[] | TokensList;
|
|
354
|
+
}
|
|
338
355
|
export interface TokenizerThis {
|
|
339
356
|
lexer: _Lexer;
|
|
340
357
|
}
|
|
@@ -356,6 +373,10 @@ export interface RendererExtension {
|
|
|
356
373
|
renderer: RendererExtensionFunction;
|
|
357
374
|
}
|
|
358
375
|
export type TokenizerAndRendererExtension = TokenizerExtension | RendererExtension | (TokenizerExtension & RendererExtension);
|
|
376
|
+
export type HooksApi = Omit<_Hooks, "constructor" | "options">;
|
|
377
|
+
export type HooksObject = {
|
|
378
|
+
[K in keyof HooksApi]?: (...args: Parameters<HooksApi[K]>) => ReturnType<HooksApi[K]> | Promise<ReturnType<HooksApi[K]>>;
|
|
379
|
+
};
|
|
359
380
|
export type RendererApi = Omit<_Renderer, "constructor" | "options">;
|
|
360
381
|
export type RendererObject = {
|
|
361
382
|
[K in keyof RendererApi]?: (...args: Parameters<RendererApi[K]>) => ReturnType<RendererApi[K]> | false;
|
|
@@ -384,13 +405,10 @@ export interface MarkedExtension {
|
|
|
384
405
|
/**
|
|
385
406
|
* Hooks are methods that hook into some part of marked.
|
|
386
407
|
* preprocess is called to process markdown before sending it to marked.
|
|
408
|
+
* processAllTokens is called with the TokensList before walkTokens.
|
|
387
409
|
* postprocess is called to process html after marked has finished parsing.
|
|
388
410
|
*/
|
|
389
|
-
hooks?:
|
|
390
|
-
preprocess: (markdown: string) => string | Promise<string>;
|
|
391
|
-
postprocess: (html: string) => string | Promise<string>;
|
|
392
|
-
options?: MarkedOptions;
|
|
393
|
-
} | null;
|
|
411
|
+
hooks?: HooksObject | undefined | null;
|
|
394
412
|
/**
|
|
395
413
|
* Conform to obscure parts of markdown.pl as much as possible. Don't fix any of the original markdown bugs or poor behavior.
|
|
396
414
|
*/
|
|
@@ -417,7 +435,11 @@ export interface MarkedExtension {
|
|
|
417
435
|
*/
|
|
418
436
|
walkTokens?: ((token: Token) => void | Promise<void>) | undefined | null;
|
|
419
437
|
}
|
|
420
|
-
export interface MarkedOptions extends Omit<MarkedExtension, "renderer" | "tokenizer" | "extensions" | "walkTokens"> {
|
|
438
|
+
export interface MarkedOptions extends Omit<MarkedExtension, "hooks" | "renderer" | "tokenizer" | "extensions" | "walkTokens"> {
|
|
439
|
+
/**
|
|
440
|
+
* Hooks are methods that hook into some part of marked.
|
|
441
|
+
*/
|
|
442
|
+
hooks?: _Hooks | undefined | null;
|
|
421
443
|
/**
|
|
422
444
|
* Type: object Default: new Renderer()
|
|
423
445
|
*
|
|
@@ -532,19 +554,6 @@ declare class _Lexer {
|
|
|
532
554
|
*/
|
|
533
555
|
inlineTokens(src: string, tokens?: Token[]): Token[];
|
|
534
556
|
}
|
|
535
|
-
declare class _Hooks {
|
|
536
|
-
options: MarkedOptions;
|
|
537
|
-
constructor(options?: MarkedOptions);
|
|
538
|
-
static passThroughHooks: Set<string>;
|
|
539
|
-
/**
|
|
540
|
-
* Process markdown before marked
|
|
541
|
-
*/
|
|
542
|
-
preprocess(markdown: string): string;
|
|
543
|
-
/**
|
|
544
|
-
* Process HTML after marked is finished
|
|
545
|
-
*/
|
|
546
|
-
postprocess(html: string): string;
|
|
547
|
-
}
|
|
548
557
|
declare function _getDefaults(): MarkedOptions;
|
|
549
558
|
declare let _defaults: MarkedOptions;
|
|
550
559
|
export type MaybePromise = void | Promise<void>;
|
package/lib/marked.d.ts
CHANGED
|
@@ -335,6 +335,23 @@ declare class _Tokenizer {
|
|
|
335
335
|
url(src: string): Tokens.Link | undefined;
|
|
336
336
|
inlineText(src: string): Tokens.Text | undefined;
|
|
337
337
|
}
|
|
338
|
+
declare class _Hooks {
|
|
339
|
+
options: MarkedOptions;
|
|
340
|
+
constructor(options?: MarkedOptions);
|
|
341
|
+
static passThroughHooks: Set<string>;
|
|
342
|
+
/**
|
|
343
|
+
* Process markdown before marked
|
|
344
|
+
*/
|
|
345
|
+
preprocess(markdown: string): string;
|
|
346
|
+
/**
|
|
347
|
+
* Process HTML after marked is finished
|
|
348
|
+
*/
|
|
349
|
+
postprocess(html: string): string;
|
|
350
|
+
/**
|
|
351
|
+
* Process all tokens before walk tokens
|
|
352
|
+
*/
|
|
353
|
+
processAllTokens(tokens: Token[] | TokensList): Token[] | TokensList;
|
|
354
|
+
}
|
|
338
355
|
export interface TokenizerThis {
|
|
339
356
|
lexer: _Lexer;
|
|
340
357
|
}
|
|
@@ -356,6 +373,10 @@ export interface RendererExtension {
|
|
|
356
373
|
renderer: RendererExtensionFunction;
|
|
357
374
|
}
|
|
358
375
|
export type TokenizerAndRendererExtension = TokenizerExtension | RendererExtension | (TokenizerExtension & RendererExtension);
|
|
376
|
+
export type HooksApi = Omit<_Hooks, "constructor" | "options">;
|
|
377
|
+
export type HooksObject = {
|
|
378
|
+
[K in keyof HooksApi]?: (...args: Parameters<HooksApi[K]>) => ReturnType<HooksApi[K]> | Promise<ReturnType<HooksApi[K]>>;
|
|
379
|
+
};
|
|
359
380
|
export type RendererApi = Omit<_Renderer, "constructor" | "options">;
|
|
360
381
|
export type RendererObject = {
|
|
361
382
|
[K in keyof RendererApi]?: (...args: Parameters<RendererApi[K]>) => ReturnType<RendererApi[K]> | false;
|
|
@@ -384,13 +405,10 @@ export interface MarkedExtension {
|
|
|
384
405
|
/**
|
|
385
406
|
* Hooks are methods that hook into some part of marked.
|
|
386
407
|
* preprocess is called to process markdown before sending it to marked.
|
|
408
|
+
* processAllTokens is called with the TokensList before walkTokens.
|
|
387
409
|
* postprocess is called to process html after marked has finished parsing.
|
|
388
410
|
*/
|
|
389
|
-
hooks?:
|
|
390
|
-
preprocess: (markdown: string) => string | Promise<string>;
|
|
391
|
-
postprocess: (html: string) => string | Promise<string>;
|
|
392
|
-
options?: MarkedOptions;
|
|
393
|
-
} | null;
|
|
411
|
+
hooks?: HooksObject | undefined | null;
|
|
394
412
|
/**
|
|
395
413
|
* Conform to obscure parts of markdown.pl as much as possible. Don't fix any of the original markdown bugs or poor behavior.
|
|
396
414
|
*/
|
|
@@ -417,7 +435,11 @@ export interface MarkedExtension {
|
|
|
417
435
|
*/
|
|
418
436
|
walkTokens?: ((token: Token) => void | Promise<void>) | undefined | null;
|
|
419
437
|
}
|
|
420
|
-
export interface MarkedOptions extends Omit<MarkedExtension, "renderer" | "tokenizer" | "extensions" | "walkTokens"> {
|
|
438
|
+
export interface MarkedOptions extends Omit<MarkedExtension, "hooks" | "renderer" | "tokenizer" | "extensions" | "walkTokens"> {
|
|
439
|
+
/**
|
|
440
|
+
* Hooks are methods that hook into some part of marked.
|
|
441
|
+
*/
|
|
442
|
+
hooks?: _Hooks | undefined | null;
|
|
421
443
|
/**
|
|
422
444
|
* Type: object Default: new Renderer()
|
|
423
445
|
*
|
|
@@ -532,19 +554,6 @@ declare class _Lexer {
|
|
|
532
554
|
*/
|
|
533
555
|
inlineTokens(src: string, tokens?: Token[]): Token[];
|
|
534
556
|
}
|
|
535
|
-
declare class _Hooks {
|
|
536
|
-
options: MarkedOptions;
|
|
537
|
-
constructor(options?: MarkedOptions);
|
|
538
|
-
static passThroughHooks: Set<string>;
|
|
539
|
-
/**
|
|
540
|
-
* Process markdown before marked
|
|
541
|
-
*/
|
|
542
|
-
preprocess(markdown: string): string;
|
|
543
|
-
/**
|
|
544
|
-
* Process HTML after marked is finished
|
|
545
|
-
*/
|
|
546
|
-
postprocess(html: string): string;
|
|
547
|
-
}
|
|
548
557
|
declare function _getDefaults(): MarkedOptions;
|
|
549
558
|
declare let _defaults: MarkedOptions;
|
|
550
559
|
export type MaybePromise = void | Promise<void>;
|
package/lib/marked.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* marked v11.0
|
|
2
|
+
* marked v11.1.0 - a markdown parser
|
|
3
3
|
* Copyright (c) 2011-2023, Christopher Jeffrey. (MIT Licensed)
|
|
4
4
|
* https://github.com/markedjs/marked
|
|
5
5
|
*/
|
|
@@ -2022,7 +2022,8 @@ class _Hooks {
|
|
|
2022
2022
|
}
|
|
2023
2023
|
static passThroughHooks = new Set([
|
|
2024
2024
|
'preprocess',
|
|
2025
|
-
'postprocess'
|
|
2025
|
+
'postprocess',
|
|
2026
|
+
'processAllTokens'
|
|
2026
2027
|
]);
|
|
2027
2028
|
/**
|
|
2028
2029
|
* Process markdown before marked
|
|
@@ -2036,6 +2037,12 @@ class _Hooks {
|
|
|
2036
2037
|
postprocess(html) {
|
|
2037
2038
|
return html;
|
|
2038
2039
|
}
|
|
2040
|
+
/**
|
|
2041
|
+
* Process all tokens before walk tokens
|
|
2042
|
+
*/
|
|
2043
|
+
processAllTokens(tokens) {
|
|
2044
|
+
return tokens;
|
|
2045
|
+
}
|
|
2039
2046
|
}
|
|
2040
2047
|
|
|
2041
2048
|
class Marked {
|
|
@@ -2222,6 +2229,7 @@ class Marked {
|
|
|
2222
2229
|
const hooksFunc = pack.hooks[hooksProp];
|
|
2223
2230
|
const prevHook = hooks[hooksProp];
|
|
2224
2231
|
if (_Hooks.passThroughHooks.has(prop)) {
|
|
2232
|
+
// @ts-expect-error cannot type hook function dynamically
|
|
2225
2233
|
hooks[hooksProp] = (arg) => {
|
|
2226
2234
|
if (this.defaults.async) {
|
|
2227
2235
|
return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
|
|
@@ -2233,6 +2241,7 @@ class Marked {
|
|
|
2233
2241
|
};
|
|
2234
2242
|
}
|
|
2235
2243
|
else {
|
|
2244
|
+
// @ts-expect-error cannot type hook function dynamically
|
|
2236
2245
|
hooks[hooksProp] = (...args) => {
|
|
2237
2246
|
let ret = hooksFunc.apply(hooks, args);
|
|
2238
2247
|
if (ret === false) {
|
|
@@ -2297,6 +2306,7 @@ class Marked {
|
|
|
2297
2306
|
if (opt.async) {
|
|
2298
2307
|
return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
|
|
2299
2308
|
.then(src => lexer(src, opt))
|
|
2309
|
+
.then(tokens => opt.hooks ? opt.hooks.processAllTokens(tokens) : tokens)
|
|
2300
2310
|
.then(tokens => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens)
|
|
2301
2311
|
.then(tokens => parser(tokens, opt))
|
|
2302
2312
|
.then(html => opt.hooks ? opt.hooks.postprocess(html) : html)
|
|
@@ -2306,7 +2316,10 @@ class Marked {
|
|
|
2306
2316
|
if (opt.hooks) {
|
|
2307
2317
|
src = opt.hooks.preprocess(src);
|
|
2308
2318
|
}
|
|
2309
|
-
|
|
2319
|
+
let tokens = lexer(src, opt);
|
|
2320
|
+
if (opt.hooks) {
|
|
2321
|
+
tokens = opt.hooks.processAllTokens(tokens);
|
|
2322
|
+
}
|
|
2310
2323
|
if (opt.walkTokens) {
|
|
2311
2324
|
this.walkTokens(tokens, opt.walkTokens);
|
|
2312
2325
|
}
|