marked 14.0.0 → 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.d.cts CHANGED
@@ -271,54 +271,6 @@ declare const inlineNormal: {
271
271
  url: RegExp;
272
272
  };
273
273
  export type InlineKeys = keyof typeof inlineNormal;
274
- /**
275
- * exports
276
- */
277
- export declare const block: {
278
- normal: {
279
- blockquote: RegExp;
280
- code: RegExp;
281
- def: RegExp;
282
- fences: RegExp;
283
- heading: RegExp;
284
- hr: RegExp;
285
- html: RegExp;
286
- lheading: RegExp;
287
- list: RegExp;
288
- newline: RegExp;
289
- paragraph: RegExp;
290
- table: RegExp;
291
- text: RegExp;
292
- };
293
- gfm: Record<"code" | "blockquote" | "hr" | "html" | "table" | "text" | "heading" | "list" | "paragraph" | "def" | "fences" | "lheading" | "newline", RegExp>;
294
- pedantic: Record<"code" | "blockquote" | "hr" | "html" | "table" | "text" | "heading" | "list" | "paragraph" | "def" | "fences" | "lheading" | "newline", RegExp>;
295
- };
296
- export declare const inline: {
297
- normal: {
298
- _backpedal: RegExp;
299
- anyPunctuation: RegExp;
300
- autolink: RegExp;
301
- blockSkip: RegExp;
302
- br: RegExp;
303
- code: RegExp;
304
- del: RegExp;
305
- emStrongLDelim: RegExp;
306
- emStrongRDelimAst: RegExp;
307
- emStrongRDelimUnd: RegExp;
308
- escape: RegExp;
309
- link: RegExp;
310
- nolink: RegExp;
311
- punctuation: RegExp;
312
- reflink: RegExp;
313
- reflinkSearch: RegExp;
314
- tag: RegExp;
315
- text: RegExp;
316
- url: RegExp;
317
- };
318
- gfm: Record<"link" | "code" | "url" | "br" | "del" | "text" | "escape" | "tag" | "reflink" | "autolink" | "nolink" | "_backpedal" | "anyPunctuation" | "blockSkip" | "emStrongLDelim" | "emStrongRDelimAst" | "emStrongRDelimUnd" | "punctuation" | "reflinkSearch", RegExp>;
319
- breaks: Record<"link" | "code" | "url" | "br" | "del" | "text" | "escape" | "tag" | "reflink" | "autolink" | "nolink" | "_backpedal" | "anyPunctuation" | "blockSkip" | "emStrongLDelim" | "emStrongRDelimAst" | "emStrongRDelimUnd" | "punctuation" | "reflinkSearch", RegExp>;
320
- pedantic: Record<"link" | "code" | "url" | "br" | "del" | "text" | "escape" | "tag" | "reflink" | "autolink" | "nolink" | "_backpedal" | "anyPunctuation" | "blockSkip" | "emStrongLDelim" | "emStrongRDelimAst" | "emStrongRDelimUnd" | "punctuation" | "reflinkSearch", RegExp>;
321
- };
322
274
  export interface Rules {
323
275
  block: Record<BlockKeys, RegExp>;
324
276
  inline: Record<InlineKeys, RegExp>;
@@ -358,6 +310,7 @@ declare class _Tokenizer {
358
310
  }
359
311
  declare class _Hooks {
360
312
  options: MarkedOptions;
313
+ block: boolean | undefined;
361
314
  constructor(options?: MarkedOptions);
362
315
  static passThroughHooks: Set<string>;
363
316
  /**
@@ -372,6 +325,14 @@ declare class _Hooks {
372
325
  * Process all tokens before walk tokens
373
326
  */
374
327
  processAllTokens(tokens: Token[] | TokensList): Token[] | TokensList;
328
+ /**
329
+ * Provide function to tokenize markdown
330
+ */
331
+ provideLexer(): typeof _Lexer.lexInline;
332
+ /**
333
+ * Provide function to parse tokens
334
+ */
335
+ provideParser(): typeof _Parser.parse;
375
336
  }
376
337
  export interface TokenizerThis {
377
338
  lexer: _Lexer;
@@ -394,7 +355,7 @@ export interface RendererExtension {
394
355
  renderer: RendererExtensionFunction;
395
356
  }
396
357
  export type TokenizerAndRendererExtension = TokenizerExtension | RendererExtension | (TokenizerExtension & RendererExtension);
397
- export type HooksApi = Omit<_Hooks, "constructor" | "options">;
358
+ export type HooksApi = Omit<_Hooks, "constructor" | "options" | "block">;
398
359
  export type HooksObject = {
399
360
  [K in keyof HooksApi]?: (this: _Hooks, ...args: Parameters<HooksApi[K]>) => ReturnType<HooksApi[K]> | Promise<ReturnType<HooksApi[K]>>;
400
361
  };
@@ -428,6 +389,8 @@ export interface MarkedExtension {
428
389
  * preprocess is called to process markdown before sending it to marked.
429
390
  * processAllTokens is called with the TokensList before walkTokens.
430
391
  * postprocess is called to process html after marked has finished parsing.
392
+ * provideLexer is called to provide a function to tokenize markdown.
393
+ * provideParser is called to provide a function to parse tokens.
431
394
  */
432
395
  hooks?: HooksObject | undefined | null;
433
396
  /**
package/lib/marked.d.ts CHANGED
@@ -271,54 +271,6 @@ declare const inlineNormal: {
271
271
  url: RegExp;
272
272
  };
273
273
  export type InlineKeys = keyof typeof inlineNormal;
274
- /**
275
- * exports
276
- */
277
- export declare const block: {
278
- normal: {
279
- blockquote: RegExp;
280
- code: RegExp;
281
- def: RegExp;
282
- fences: RegExp;
283
- heading: RegExp;
284
- hr: RegExp;
285
- html: RegExp;
286
- lheading: RegExp;
287
- list: RegExp;
288
- newline: RegExp;
289
- paragraph: RegExp;
290
- table: RegExp;
291
- text: RegExp;
292
- };
293
- gfm: Record<"code" | "blockquote" | "hr" | "html" | "table" | "text" | "heading" | "list" | "paragraph" | "def" | "fences" | "lheading" | "newline", RegExp>;
294
- pedantic: Record<"code" | "blockquote" | "hr" | "html" | "table" | "text" | "heading" | "list" | "paragraph" | "def" | "fences" | "lheading" | "newline", RegExp>;
295
- };
296
- export declare const inline: {
297
- normal: {
298
- _backpedal: RegExp;
299
- anyPunctuation: RegExp;
300
- autolink: RegExp;
301
- blockSkip: RegExp;
302
- br: RegExp;
303
- code: RegExp;
304
- del: RegExp;
305
- emStrongLDelim: RegExp;
306
- emStrongRDelimAst: RegExp;
307
- emStrongRDelimUnd: RegExp;
308
- escape: RegExp;
309
- link: RegExp;
310
- nolink: RegExp;
311
- punctuation: RegExp;
312
- reflink: RegExp;
313
- reflinkSearch: RegExp;
314
- tag: RegExp;
315
- text: RegExp;
316
- url: RegExp;
317
- };
318
- gfm: Record<"link" | "code" | "url" | "br" | "del" | "text" | "escape" | "tag" | "reflink" | "autolink" | "nolink" | "_backpedal" | "anyPunctuation" | "blockSkip" | "emStrongLDelim" | "emStrongRDelimAst" | "emStrongRDelimUnd" | "punctuation" | "reflinkSearch", RegExp>;
319
- breaks: Record<"link" | "code" | "url" | "br" | "del" | "text" | "escape" | "tag" | "reflink" | "autolink" | "nolink" | "_backpedal" | "anyPunctuation" | "blockSkip" | "emStrongLDelim" | "emStrongRDelimAst" | "emStrongRDelimUnd" | "punctuation" | "reflinkSearch", RegExp>;
320
- pedantic: Record<"link" | "code" | "url" | "br" | "del" | "text" | "escape" | "tag" | "reflink" | "autolink" | "nolink" | "_backpedal" | "anyPunctuation" | "blockSkip" | "emStrongLDelim" | "emStrongRDelimAst" | "emStrongRDelimUnd" | "punctuation" | "reflinkSearch", RegExp>;
321
- };
322
274
  export interface Rules {
323
275
  block: Record<BlockKeys, RegExp>;
324
276
  inline: Record<InlineKeys, RegExp>;
@@ -358,6 +310,7 @@ declare class _Tokenizer {
358
310
  }
359
311
  declare class _Hooks {
360
312
  options: MarkedOptions;
313
+ block: boolean | undefined;
361
314
  constructor(options?: MarkedOptions);
362
315
  static passThroughHooks: Set<string>;
363
316
  /**
@@ -372,6 +325,14 @@ declare class _Hooks {
372
325
  * Process all tokens before walk tokens
373
326
  */
374
327
  processAllTokens(tokens: Token[] | TokensList): Token[] | TokensList;
328
+ /**
329
+ * Provide function to tokenize markdown
330
+ */
331
+ provideLexer(): typeof _Lexer.lexInline;
332
+ /**
333
+ * Provide function to parse tokens
334
+ */
335
+ provideParser(): typeof _Parser.parse;
375
336
  }
376
337
  export interface TokenizerThis {
377
338
  lexer: _Lexer;
@@ -394,7 +355,7 @@ export interface RendererExtension {
394
355
  renderer: RendererExtensionFunction;
395
356
  }
396
357
  export type TokenizerAndRendererExtension = TokenizerExtension | RendererExtension | (TokenizerExtension & RendererExtension);
397
- export type HooksApi = Omit<_Hooks, "constructor" | "options">;
358
+ export type HooksApi = Omit<_Hooks, "constructor" | "options" | "block">;
398
359
  export type HooksObject = {
399
360
  [K in keyof HooksApi]?: (this: _Hooks, ...args: Parameters<HooksApi[K]>) => ReturnType<HooksApi[K]> | Promise<ReturnType<HooksApi[K]>>;
400
361
  };
@@ -428,6 +389,8 @@ export interface MarkedExtension {
428
389
  * preprocess is called to process markdown before sending it to marked.
429
390
  * processAllTokens is called with the TokensList before walkTokens.
430
391
  * postprocess is called to process html after marked has finished parsing.
392
+ * provideLexer is called to provide a function to tokenize markdown.
393
+ * provideParser is called to provide a function to parse tokens.
431
394
  */
432
395
  hooks?: HooksObject | undefined | null;
433
396
  /**
package/lib/marked.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * marked v14.0.0 - a markdown parser
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
  */
@@ -2076,6 +2076,7 @@ class _Parser {
2076
2076
 
2077
2077
  class _Hooks {
2078
2078
  options;
2079
+ block;
2079
2080
  constructor(options) {
2080
2081
  this.options = options || _defaults;
2081
2082
  }
@@ -2102,13 +2103,25 @@ class _Hooks {
2102
2103
  processAllTokens(tokens) {
2103
2104
  return tokens;
2104
2105
  }
2106
+ /**
2107
+ * Provide function to tokenize markdown
2108
+ */
2109
+ provideLexer() {
2110
+ return this.block ? _Lexer.lex : _Lexer.lexInline;
2111
+ }
2112
+ /**
2113
+ * Provide function to parse tokens
2114
+ */
2115
+ provideParser() {
2116
+ return this.block ? _Parser.parse : _Parser.parseInline;
2117
+ }
2105
2118
  }
2106
2119
 
2107
2120
  class Marked {
2108
2121
  defaults = _getDefaults();
2109
2122
  options = this.setOptions;
2110
- parse = this.parseMarkdown(_Lexer.lex, _Parser.parse);
2111
- parseInline = this.parseMarkdown(_Lexer.lexInline, _Parser.parseInline);
2123
+ parse = this.parseMarkdown(true);
2124
+ parseInline = this.parseMarkdown(false);
2112
2125
  Parser = _Parser;
2113
2126
  Renderer = _Renderer;
2114
2127
  TextRenderer = _TextRenderer;
@@ -2281,8 +2294,8 @@ class Marked {
2281
2294
  if (!(prop in hooks)) {
2282
2295
  throw new Error(`hook '${prop}' does not exist`);
2283
2296
  }
2284
- if (prop === 'options') {
2285
- // ignore options property
2297
+ if (['options', 'block'].includes(prop)) {
2298
+ // ignore options and block properties
2286
2299
  continue;
2287
2300
  }
2288
2301
  const hooksProp = prop;
@@ -2340,7 +2353,7 @@ class Marked {
2340
2353
  parser(tokens, options) {
2341
2354
  return _Parser.parse(tokens, options ?? this.defaults);
2342
2355
  }
2343
- parseMarkdown(lexer, parser) {
2356
+ parseMarkdown(blockType) {
2344
2357
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2345
2358
  const parse = (src, options) => {
2346
2359
  const origOpt = { ...options };
@@ -2360,7 +2373,10 @@ class Marked {
2360
2373
  }
2361
2374
  if (opt.hooks) {
2362
2375
  opt.hooks.options = opt;
2376
+ opt.hooks.block = blockType;
2363
2377
  }
2378
+ const lexer = opt.hooks ? opt.hooks.provideLexer() : (blockType ? _Lexer.lex : _Lexer.lexInline);
2379
+ const parser = opt.hooks ? opt.hooks.provideParser() : (blockType ? _Parser.parse : _Parser.parseInline);
2364
2380
  if (opt.async) {
2365
2381
  return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
2366
2382
  .then(src => lexer(src, opt))