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.cjs 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
  */
@@ -2078,6 +2078,7 @@ class _Parser {
2078
2078
 
2079
2079
  class _Hooks {
2080
2080
  options;
2081
+ block;
2081
2082
  constructor(options) {
2082
2083
  this.options = options || exports.defaults;
2083
2084
  }
@@ -2104,13 +2105,25 @@ class _Hooks {
2104
2105
  processAllTokens(tokens) {
2105
2106
  return tokens;
2106
2107
  }
2108
+ /**
2109
+ * Provide function to tokenize markdown
2110
+ */
2111
+ provideLexer() {
2112
+ return this.block ? _Lexer.lex : _Lexer.lexInline;
2113
+ }
2114
+ /**
2115
+ * Provide function to parse tokens
2116
+ */
2117
+ provideParser() {
2118
+ return this.block ? _Parser.parse : _Parser.parseInline;
2119
+ }
2107
2120
  }
2108
2121
 
2109
2122
  class Marked {
2110
2123
  defaults = _getDefaults();
2111
2124
  options = this.setOptions;
2112
- parse = this.parseMarkdown(_Lexer.lex, _Parser.parse);
2113
- parseInline = this.parseMarkdown(_Lexer.lexInline, _Parser.parseInline);
2125
+ parse = this.parseMarkdown(true);
2126
+ parseInline = this.parseMarkdown(false);
2114
2127
  Parser = _Parser;
2115
2128
  Renderer = _Renderer;
2116
2129
  TextRenderer = _TextRenderer;
@@ -2283,8 +2296,8 @@ class Marked {
2283
2296
  if (!(prop in hooks)) {
2284
2297
  throw new Error(`hook '${prop}' does not exist`);
2285
2298
  }
2286
- if (prop === 'options') {
2287
- // ignore options property
2299
+ if (['options', 'block'].includes(prop)) {
2300
+ // ignore options and block properties
2288
2301
  continue;
2289
2302
  }
2290
2303
  const hooksProp = prop;
@@ -2342,7 +2355,7 @@ class Marked {
2342
2355
  parser(tokens, options) {
2343
2356
  return _Parser.parse(tokens, options ?? this.defaults);
2344
2357
  }
2345
- parseMarkdown(lexer, parser) {
2358
+ parseMarkdown(blockType) {
2346
2359
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2347
2360
  const parse = (src, options) => {
2348
2361
  const origOpt = { ...options };
@@ -2362,7 +2375,10 @@ class Marked {
2362
2375
  }
2363
2376
  if (opt.hooks) {
2364
2377
  opt.hooks.options = opt;
2378
+ opt.hooks.block = blockType;
2365
2379
  }
2380
+ const lexer = opt.hooks ? opt.hooks.provideLexer() : (blockType ? _Lexer.lex : _Lexer.lexInline);
2381
+ const parser = opt.hooks ? opt.hooks.provideParser() : (blockType ? _Parser.parse : _Parser.parseInline);
2366
2382
  if (opt.async) {
2367
2383
  return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
2368
2384
  .then(src => lexer(src, opt))