marked 11.0.1 → 11.1.1

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.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * marked v11.0.1 - a markdown parser
2
+ * marked v11.1.1 - a markdown parser
3
3
  * Copyright (c) 2011-2023, Christopher Jeffrey. (MIT Licensed)
4
4
  * https://github.com/markedjs/marked
5
5
  */
@@ -1266,10 +1266,11 @@
1266
1266
  src = src
1267
1267
  .replace(/\r\n|\r/g, '\n');
1268
1268
  this.blockTokens(src, this.tokens);
1269
- let next;
1270
- while (next = this.inlineQueue.shift()) {
1269
+ for (let i = 0; i < this.inlineQueue.length; i++) {
1270
+ const next = this.inlineQueue[i];
1271
1271
  this.inlineTokens(next.src, next.tokens);
1272
1272
  }
1273
+ this.inlineQueue = [];
1273
1274
  return this.tokens;
1274
1275
  }
1275
1276
  blockTokens(src, tokens = []) {
@@ -2028,7 +2029,8 @@
2028
2029
  }
2029
2030
  static passThroughHooks = new Set([
2030
2031
  'preprocess',
2031
- 'postprocess'
2032
+ 'postprocess',
2033
+ 'processAllTokens'
2032
2034
  ]);
2033
2035
  /**
2034
2036
  * Process markdown before marked
@@ -2042,6 +2044,12 @@
2042
2044
  postprocess(html) {
2043
2045
  return html;
2044
2046
  }
2047
+ /**
2048
+ * Process all tokens before walk tokens
2049
+ */
2050
+ processAllTokens(tokens) {
2051
+ return tokens;
2052
+ }
2045
2053
  }
2046
2054
 
2047
2055
  class Marked {
@@ -2228,6 +2236,7 @@
2228
2236
  const hooksFunc = pack.hooks[hooksProp];
2229
2237
  const prevHook = hooks[hooksProp];
2230
2238
  if (_Hooks.passThroughHooks.has(prop)) {
2239
+ // @ts-expect-error cannot type hook function dynamically
2231
2240
  hooks[hooksProp] = (arg) => {
2232
2241
  if (this.defaults.async) {
2233
2242
  return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
@@ -2239,6 +2248,7 @@
2239
2248
  };
2240
2249
  }
2241
2250
  else {
2251
+ // @ts-expect-error cannot type hook function dynamically
2242
2252
  hooks[hooksProp] = (...args) => {
2243
2253
  let ret = hooksFunc.apply(hooks, args);
2244
2254
  if (ret === false) {
@@ -2303,6 +2313,7 @@
2303
2313
  if (opt.async) {
2304
2314
  return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
2305
2315
  .then(src => lexer(src, opt))
2316
+ .then(tokens => opt.hooks ? opt.hooks.processAllTokens(tokens) : tokens)
2306
2317
  .then(tokens => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens)
2307
2318
  .then(tokens => parser(tokens, opt))
2308
2319
  .then(html => opt.hooks ? opt.hooks.postprocess(html) : html)
@@ -2312,7 +2323,10 @@
2312
2323
  if (opt.hooks) {
2313
2324
  src = opt.hooks.preprocess(src);
2314
2325
  }
2315
- const tokens = lexer(src, opt);
2326
+ let tokens = lexer(src, opt);
2327
+ if (opt.hooks) {
2328
+ tokens = opt.hooks.processAllTokens(tokens);
2329
+ }
2316
2330
  if (opt.walkTokens) {
2317
2331
  this.walkTokens(tokens, opt.walkTokens);
2318
2332
  }