marked 7.0.1 → 7.0.3

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 v7.0.1 - a markdown parser
2
+ * marked v7.0.3 - a markdown parser
3
3
  * Copyright (c) 2011-2023, Christopher Jeffrey. (MIT Licensed)
4
4
  * https://github.com/markedjs/marked
5
5
  */
@@ -191,12 +191,14 @@ function splitCells(tableRow, count) {
191
191
  if (cells.length > 0 && !cells[cells.length - 1].trim()) {
192
192
  cells.pop();
193
193
  }
194
- if (cells.length > count) {
195
- cells.splice(count);
196
- }
197
- else {
198
- while (cells.length < count)
199
- cells.push('');
194
+ if (count) {
195
+ if (cells.length > count) {
196
+ cells.splice(count);
197
+ }
198
+ else {
199
+ while (cells.length < count)
200
+ cells.push('');
201
+ }
200
202
  }
201
203
  for (; i < cells.length; i++) {
202
204
  // leading or trailing whitespace is ignored per the gfm spec
@@ -629,8 +631,7 @@ class _Tokenizer {
629
631
  if (cap) {
630
632
  const item = {
631
633
  type: 'table',
632
- // splitCells expects a number as second argument
633
- // @ts-expect-error
634
+ raw: cap[0],
634
635
  header: splitCells(cap[1]).map(c => {
635
636
  return { text: c };
636
637
  }),
@@ -638,7 +639,6 @@ class _Tokenizer {
638
639
  rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : []
639
640
  };
640
641
  if (item.header.length === item.align.length) {
641
- item.raw = cap[0];
642
642
  let l = item.align.length;
643
643
  let i, j, k, row;
644
644
  for (i = 0; i < l; i++) {
@@ -838,7 +838,8 @@ class _Tokenizer {
838
838
  return;
839
839
  const nextChar = match[1] || match[2] || '';
840
840
  if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
841
- const lLength = match[0].length - 1;
841
+ // unicode Regex counts emoji as 1 char; spread into array for proper count (used multiple times below)
842
+ const lLength = [...match[0]].length - 1;
842
843
  let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
843
844
  const endReg = match[0][0] === '*' ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
844
845
  endReg.lastIndex = 0;
@@ -848,7 +849,7 @@ class _Tokenizer {
848
849
  rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
849
850
  if (!rDelim)
850
851
  continue; // skip single * in __abc*abc__
851
- rLength = rDelim.length;
852
+ rLength = [...rDelim].length;
852
853
  if (match[3] || match[4]) { // found another Left Delim
853
854
  delimTotal += rLength;
854
855
  continue;
@@ -864,7 +865,7 @@ class _Tokenizer {
864
865
  continue; // Haven't found enough closing delimiters
865
866
  // Remove extra characters. *a*** -> *a*
866
867
  rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
867
- const raw = src.slice(0, lLength + match.index + rLength + 1);
868
+ const raw = [...src].slice(0, lLength + match.index + rLength + 1).join('');
868
869
  // Create `em` if smallest delimiter has odd char count. *a***
869
870
  if (Math.min(lLength, rLength) % 2) {
870
871
  const text = raw.slice(1, -1);
@@ -1408,7 +1409,10 @@ class _Lexer {
1408
1409
  return leading + ' '.repeat(tabs.length);
1409
1410
  });
1410
1411
  }
1411
- let token, lastToken, cutSrc, lastParagraphClipped;
1412
+ let token;
1413
+ let lastToken;
1414
+ let cutSrc;
1415
+ let lastParagraphClipped;
1412
1416
  while (src) {
1413
1417
  if (this.options.extensions
1414
1418
  && this.options.extensions.block
@@ -2258,6 +2262,7 @@ class Marked {
2258
2262
  default: {
2259
2263
  if (this.defaults.extensions && this.defaults.extensions.childTokens && this.defaults.extensions.childTokens[token.type]) { // Walk any extensions
2260
2264
  this.defaults.extensions.childTokens[token.type].forEach((childTokens) => {
2265
+ // @ts-expect-error we assume token[childToken] is an array of tokens but we can't be sure
2261
2266
  values = values.concat(this.walkTokens(token[childTokens], callback));
2262
2267
  });
2263
2268
  }
@@ -2337,14 +2342,16 @@ class Marked {
2337
2342
  if (pack.renderer) {
2338
2343
  const renderer = this.defaults.renderer || new _Renderer(this.defaults);
2339
2344
  for (const prop in pack.renderer) {
2340
- const prevRenderer = renderer[prop];
2345
+ const rendererFunc = pack.renderer[prop];
2346
+ const rendererKey = prop;
2347
+ const prevRenderer = renderer[rendererKey];
2341
2348
  // Replace renderer with func to run extension, but fall back if false
2342
- renderer[prop] = (...args) => {
2343
- let ret = pack.renderer[prop].apply(renderer, args);
2349
+ renderer[rendererKey] = (...args) => {
2350
+ let ret = rendererFunc.apply(renderer, args);
2344
2351
  if (ret === false) {
2345
2352
  ret = prevRenderer.apply(renderer, args);
2346
2353
  }
2347
- return ret;
2354
+ return ret || '';
2348
2355
  };
2349
2356
  }
2350
2357
  opts.renderer = renderer;
@@ -2352,10 +2359,12 @@ class Marked {
2352
2359
  if (pack.tokenizer) {
2353
2360
  const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
2354
2361
  for (const prop in pack.tokenizer) {
2355
- const prevTokenizer = tokenizer[prop];
2362
+ const tokenizerFunc = pack.tokenizer[prop];
2363
+ const tokenizerKey = prop;
2364
+ const prevTokenizer = tokenizer[tokenizerKey];
2356
2365
  // Replace tokenizer with func to run extension, but fall back if false
2357
- tokenizer[prop] = (...args) => {
2358
- let ret = pack.tokenizer[prop].apply(tokenizer, args);
2366
+ tokenizer[tokenizerKey] = (...args) => {
2367
+ let ret = tokenizerFunc.apply(tokenizer, args);
2359
2368
  if (ret === false) {
2360
2369
  ret = prevTokenizer.apply(tokenizer, args);
2361
2370
  }
@@ -2368,21 +2377,23 @@ class Marked {
2368
2377
  if (pack.hooks) {
2369
2378
  const hooks = this.defaults.hooks || new _Hooks();
2370
2379
  for (const prop in pack.hooks) {
2371
- const prevHook = hooks[prop];
2380
+ const hooksFunc = pack.hooks[prop];
2381
+ const hooksKey = prop;
2382
+ const prevHook = hooks[hooksKey];
2372
2383
  if (_Hooks.passThroughHooks.has(prop)) {
2373
- hooks[prop] = (arg) => {
2384
+ hooks[hooksKey] = (arg) => {
2374
2385
  if (this.defaults.async) {
2375
- return Promise.resolve(pack.hooks[prop].call(hooks, arg)).then(ret => {
2386
+ return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
2376
2387
  return prevHook.call(hooks, ret);
2377
2388
  });
2378
2389
  }
2379
- const ret = pack.hooks[prop].call(hooks, arg);
2390
+ const ret = hooksFunc.call(hooks, arg);
2380
2391
  return prevHook.call(hooks, ret);
2381
2392
  };
2382
2393
  }
2383
2394
  else {
2384
- hooks[prop] = (...args) => {
2385
- let ret = pack.hooks[prop].apply(hooks, args);
2395
+ hooks[hooksKey] = (...args) => {
2396
+ let ret = hooksFunc.apply(hooks, args);
2386
2397
  if (ret === false) {
2387
2398
  ret = prevHook.apply(hooks, args);
2388
2399
  }