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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * marked v11.0.1 - a markdown parser
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
  */
@@ -2024,7 +2024,8 @@ class _Hooks {
2024
2024
  }
2025
2025
  static passThroughHooks = new Set([
2026
2026
  'preprocess',
2027
- 'postprocess'
2027
+ 'postprocess',
2028
+ 'processAllTokens'
2028
2029
  ]);
2029
2030
  /**
2030
2031
  * Process markdown before marked
@@ -2038,6 +2039,12 @@ class _Hooks {
2038
2039
  postprocess(html) {
2039
2040
  return html;
2040
2041
  }
2042
+ /**
2043
+ * Process all tokens before walk tokens
2044
+ */
2045
+ processAllTokens(tokens) {
2046
+ return tokens;
2047
+ }
2041
2048
  }
2042
2049
 
2043
2050
  class Marked {
@@ -2224,6 +2231,7 @@ class Marked {
2224
2231
  const hooksFunc = pack.hooks[hooksProp];
2225
2232
  const prevHook = hooks[hooksProp];
2226
2233
  if (_Hooks.passThroughHooks.has(prop)) {
2234
+ // @ts-expect-error cannot type hook function dynamically
2227
2235
  hooks[hooksProp] = (arg) => {
2228
2236
  if (this.defaults.async) {
2229
2237
  return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
@@ -2235,6 +2243,7 @@ class Marked {
2235
2243
  };
2236
2244
  }
2237
2245
  else {
2246
+ // @ts-expect-error cannot type hook function dynamically
2238
2247
  hooks[hooksProp] = (...args) => {
2239
2248
  let ret = hooksFunc.apply(hooks, args);
2240
2249
  if (ret === false) {
@@ -2299,6 +2308,7 @@ class Marked {
2299
2308
  if (opt.async) {
2300
2309
  return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
2301
2310
  .then(src => lexer(src, opt))
2311
+ .then(tokens => opt.hooks ? opt.hooks.processAllTokens(tokens) : tokens)
2302
2312
  .then(tokens => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens)
2303
2313
  .then(tokens => parser(tokens, opt))
2304
2314
  .then(html => opt.hooks ? opt.hooks.postprocess(html) : html)
@@ -2308,7 +2318,10 @@ class Marked {
2308
2318
  if (opt.hooks) {
2309
2319
  src = opt.hooks.preprocess(src);
2310
2320
  }
2311
- const tokens = lexer(src, opt);
2321
+ let tokens = lexer(src, opt);
2322
+ if (opt.hooks) {
2323
+ tokens = opt.hooks.processAllTokens(tokens);
2324
+ }
2312
2325
  if (opt.walkTokens) {
2313
2326
  this.walkTokens(tokens, opt.walkTokens);
2314
2327
  }