marked 11.0.0 → 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 +31 -6
- package/lib/marked.cjs.map +1 -1
- package/lib/marked.d.cts +29 -20
- package/lib/marked.d.ts +29 -20
- package/lib/marked.esm.js +31 -6
- package/lib/marked.esm.js.map +1 -1
- package/lib/marked.umd.js +31 -6
- package/lib/marked.umd.js.map +1 -1
- package/man/marked.1 +1 -1
- package/marked.min.js +2 -2
- package/package.json +9 -9
package/lib/marked.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator
|
|
1
|
+
// Generated by dts-bundle-generator v9.0.0
|
|
2
2
|
|
|
3
3
|
export type Token = (Tokens.Space | Tokens.Code | Tokens.Heading | Tokens.Table | Tokens.Hr | Tokens.Blockquote | Tokens.List | Tokens.ListItem | Tokens.Paragraph | Tokens.HTML | Tokens.Text | Tokens.Def | Tokens.Escape | Tokens.Tag | Tokens.Image | Tokens.Link | Tokens.Strong | Tokens.Em | Tokens.Codespan | Tokens.Br | Tokens.Del | Tokens.Generic);
|
|
4
4
|
export declare namespace Tokens {
|
|
@@ -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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator
|
|
1
|
+
// Generated by dts-bundle-generator v9.0.0
|
|
2
2
|
|
|
3
3
|
export type Token = (Tokens.Space | Tokens.Code | Tokens.Heading | Tokens.Table | Tokens.Hr | Tokens.Blockquote | Tokens.List | Tokens.ListItem | Tokens.Paragraph | Tokens.HTML | Tokens.Text | Tokens.Def | Tokens.Escape | Tokens.Tag | Tokens.Image | Tokens.Link | Tokens.Strong | Tokens.Em | Tokens.Codespan | Tokens.Br | Tokens.Del | Tokens.Generic);
|
|
4
4
|
export declare namespace Tokens {
|
|
@@ -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.
|
|
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 {
|
|
@@ -2161,9 +2168,13 @@ class Marked {
|
|
|
2161
2168
|
if (pack.renderer) {
|
|
2162
2169
|
const renderer = this.defaults.renderer || new _Renderer(this.defaults);
|
|
2163
2170
|
for (const prop in pack.renderer) {
|
|
2164
|
-
if (!(prop in renderer)
|
|
2171
|
+
if (!(prop in renderer)) {
|
|
2165
2172
|
throw new Error(`renderer '${prop}' does not exist`);
|
|
2166
2173
|
}
|
|
2174
|
+
if (prop === 'options') {
|
|
2175
|
+
// ignore options property
|
|
2176
|
+
continue;
|
|
2177
|
+
}
|
|
2167
2178
|
const rendererProp = prop;
|
|
2168
2179
|
const rendererFunc = pack.renderer[rendererProp];
|
|
2169
2180
|
const prevRenderer = renderer[rendererProp];
|
|
@@ -2181,9 +2192,13 @@ class Marked {
|
|
|
2181
2192
|
if (pack.tokenizer) {
|
|
2182
2193
|
const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
|
|
2183
2194
|
for (const prop in pack.tokenizer) {
|
|
2184
|
-
if (!(prop in tokenizer)
|
|
2195
|
+
if (!(prop in tokenizer)) {
|
|
2185
2196
|
throw new Error(`tokenizer '${prop}' does not exist`);
|
|
2186
2197
|
}
|
|
2198
|
+
if (['options', 'rules', 'lexer'].includes(prop)) {
|
|
2199
|
+
// ignore options, rules, and lexer properties
|
|
2200
|
+
continue;
|
|
2201
|
+
}
|
|
2187
2202
|
const tokenizerProp = prop;
|
|
2188
2203
|
const tokenizerFunc = pack.tokenizer[tokenizerProp];
|
|
2189
2204
|
const prevTokenizer = tokenizer[tokenizerProp];
|
|
@@ -2203,13 +2218,18 @@ class Marked {
|
|
|
2203
2218
|
if (pack.hooks) {
|
|
2204
2219
|
const hooks = this.defaults.hooks || new _Hooks();
|
|
2205
2220
|
for (const prop in pack.hooks) {
|
|
2206
|
-
if (!(prop in hooks)
|
|
2221
|
+
if (!(prop in hooks)) {
|
|
2207
2222
|
throw new Error(`hook '${prop}' does not exist`);
|
|
2208
2223
|
}
|
|
2224
|
+
if (prop === 'options') {
|
|
2225
|
+
// ignore options property
|
|
2226
|
+
continue;
|
|
2227
|
+
}
|
|
2209
2228
|
const hooksProp = prop;
|
|
2210
2229
|
const hooksFunc = pack.hooks[hooksProp];
|
|
2211
2230
|
const prevHook = hooks[hooksProp];
|
|
2212
2231
|
if (_Hooks.passThroughHooks.has(prop)) {
|
|
2232
|
+
// @ts-expect-error cannot type hook function dynamically
|
|
2213
2233
|
hooks[hooksProp] = (arg) => {
|
|
2214
2234
|
if (this.defaults.async) {
|
|
2215
2235
|
return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
|
|
@@ -2221,6 +2241,7 @@ class Marked {
|
|
|
2221
2241
|
};
|
|
2222
2242
|
}
|
|
2223
2243
|
else {
|
|
2244
|
+
// @ts-expect-error cannot type hook function dynamically
|
|
2224
2245
|
hooks[hooksProp] = (...args) => {
|
|
2225
2246
|
let ret = hooksFunc.apply(hooks, args);
|
|
2226
2247
|
if (ret === false) {
|
|
@@ -2285,6 +2306,7 @@ class Marked {
|
|
|
2285
2306
|
if (opt.async) {
|
|
2286
2307
|
return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
|
|
2287
2308
|
.then(src => lexer(src, opt))
|
|
2309
|
+
.then(tokens => opt.hooks ? opt.hooks.processAllTokens(tokens) : tokens)
|
|
2288
2310
|
.then(tokens => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens)
|
|
2289
2311
|
.then(tokens => parser(tokens, opt))
|
|
2290
2312
|
.then(html => opt.hooks ? opt.hooks.postprocess(html) : html)
|
|
@@ -2294,7 +2316,10 @@ class Marked {
|
|
|
2294
2316
|
if (opt.hooks) {
|
|
2295
2317
|
src = opt.hooks.preprocess(src);
|
|
2296
2318
|
}
|
|
2297
|
-
|
|
2319
|
+
let tokens = lexer(src, opt);
|
|
2320
|
+
if (opt.hooks) {
|
|
2321
|
+
tokens = opt.hooks.processAllTokens(tokens);
|
|
2322
|
+
}
|
|
2298
2323
|
if (opt.walkTokens) {
|
|
2299
2324
|
this.walkTokens(tokens, opt.walkTokens);
|
|
2300
2325
|
}
|