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.umd.js 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
  */
@@ -195,12 +195,14 @@
195
195
  if (cells.length > 0 && !cells[cells.length - 1].trim()) {
196
196
  cells.pop();
197
197
  }
198
- if (cells.length > count) {
199
- cells.splice(count);
200
- }
201
- else {
202
- while (cells.length < count)
203
- cells.push('');
198
+ if (count) {
199
+ if (cells.length > count) {
200
+ cells.splice(count);
201
+ }
202
+ else {
203
+ while (cells.length < count)
204
+ cells.push('');
205
+ }
204
206
  }
205
207
  for (; i < cells.length; i++) {
206
208
  // leading or trailing whitespace is ignored per the gfm spec
@@ -633,8 +635,7 @@
633
635
  if (cap) {
634
636
  const item = {
635
637
  type: 'table',
636
- // splitCells expects a number as second argument
637
- // @ts-expect-error
638
+ raw: cap[0],
638
639
  header: splitCells(cap[1]).map(c => {
639
640
  return { text: c };
640
641
  }),
@@ -642,7 +643,6 @@
642
643
  rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : []
643
644
  };
644
645
  if (item.header.length === item.align.length) {
645
- item.raw = cap[0];
646
646
  let l = item.align.length;
647
647
  let i, j, k, row;
648
648
  for (i = 0; i < l; i++) {
@@ -842,7 +842,8 @@
842
842
  return;
843
843
  const nextChar = match[1] || match[2] || '';
844
844
  if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
845
- const lLength = match[0].length - 1;
845
+ // unicode Regex counts emoji as 1 char; spread into array for proper count (used multiple times below)
846
+ const lLength = [...match[0]].length - 1;
846
847
  let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
847
848
  const endReg = match[0][0] === '*' ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
848
849
  endReg.lastIndex = 0;
@@ -852,7 +853,7 @@
852
853
  rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
853
854
  if (!rDelim)
854
855
  continue; // skip single * in __abc*abc__
855
- rLength = rDelim.length;
856
+ rLength = [...rDelim].length;
856
857
  if (match[3] || match[4]) { // found another Left Delim
857
858
  delimTotal += rLength;
858
859
  continue;
@@ -868,7 +869,7 @@
868
869
  continue; // Haven't found enough closing delimiters
869
870
  // Remove extra characters. *a*** -> *a*
870
871
  rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
871
- const raw = src.slice(0, lLength + match.index + rLength + 1);
872
+ const raw = [...src].slice(0, lLength + match.index + rLength + 1).join('');
872
873
  // Create `em` if smallest delimiter has odd char count. *a***
873
874
  if (Math.min(lLength, rLength) % 2) {
874
875
  const text = raw.slice(1, -1);
@@ -1412,7 +1413,10 @@
1412
1413
  return leading + ' '.repeat(tabs.length);
1413
1414
  });
1414
1415
  }
1415
- let token, lastToken, cutSrc, lastParagraphClipped;
1416
+ let token;
1417
+ let lastToken;
1418
+ let cutSrc;
1419
+ let lastParagraphClipped;
1416
1420
  while (src) {
1417
1421
  if (this.options.extensions
1418
1422
  && this.options.extensions.block
@@ -2262,6 +2266,7 @@
2262
2266
  default: {
2263
2267
  if (this.defaults.extensions && this.defaults.extensions.childTokens && this.defaults.extensions.childTokens[token.type]) { // Walk any extensions
2264
2268
  this.defaults.extensions.childTokens[token.type].forEach((childTokens) => {
2269
+ // @ts-expect-error we assume token[childToken] is an array of tokens but we can't be sure
2265
2270
  values = values.concat(this.walkTokens(token[childTokens], callback));
2266
2271
  });
2267
2272
  }
@@ -2341,14 +2346,16 @@
2341
2346
  if (pack.renderer) {
2342
2347
  const renderer = this.defaults.renderer || new _Renderer(this.defaults);
2343
2348
  for (const prop in pack.renderer) {
2344
- const prevRenderer = renderer[prop];
2349
+ const rendererFunc = pack.renderer[prop];
2350
+ const rendererKey = prop;
2351
+ const prevRenderer = renderer[rendererKey];
2345
2352
  // Replace renderer with func to run extension, but fall back if false
2346
- renderer[prop] = (...args) => {
2347
- let ret = pack.renderer[prop].apply(renderer, args);
2353
+ renderer[rendererKey] = (...args) => {
2354
+ let ret = rendererFunc.apply(renderer, args);
2348
2355
  if (ret === false) {
2349
2356
  ret = prevRenderer.apply(renderer, args);
2350
2357
  }
2351
- return ret;
2358
+ return ret || '';
2352
2359
  };
2353
2360
  }
2354
2361
  opts.renderer = renderer;
@@ -2356,10 +2363,12 @@
2356
2363
  if (pack.tokenizer) {
2357
2364
  const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
2358
2365
  for (const prop in pack.tokenizer) {
2359
- const prevTokenizer = tokenizer[prop];
2366
+ const tokenizerFunc = pack.tokenizer[prop];
2367
+ const tokenizerKey = prop;
2368
+ const prevTokenizer = tokenizer[tokenizerKey];
2360
2369
  // Replace tokenizer with func to run extension, but fall back if false
2361
- tokenizer[prop] = (...args) => {
2362
- let ret = pack.tokenizer[prop].apply(tokenizer, args);
2370
+ tokenizer[tokenizerKey] = (...args) => {
2371
+ let ret = tokenizerFunc.apply(tokenizer, args);
2363
2372
  if (ret === false) {
2364
2373
  ret = prevTokenizer.apply(tokenizer, args);
2365
2374
  }
@@ -2372,21 +2381,23 @@
2372
2381
  if (pack.hooks) {
2373
2382
  const hooks = this.defaults.hooks || new _Hooks();
2374
2383
  for (const prop in pack.hooks) {
2375
- const prevHook = hooks[prop];
2384
+ const hooksFunc = pack.hooks[prop];
2385
+ const hooksKey = prop;
2386
+ const prevHook = hooks[hooksKey];
2376
2387
  if (_Hooks.passThroughHooks.has(prop)) {
2377
- hooks[prop] = (arg) => {
2388
+ hooks[hooksKey] = (arg) => {
2378
2389
  if (this.defaults.async) {
2379
- return Promise.resolve(pack.hooks[prop].call(hooks, arg)).then(ret => {
2390
+ return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
2380
2391
  return prevHook.call(hooks, ret);
2381
2392
  });
2382
2393
  }
2383
- const ret = pack.hooks[prop].call(hooks, arg);
2394
+ const ret = hooksFunc.call(hooks, arg);
2384
2395
  return prevHook.call(hooks, ret);
2385
2396
  };
2386
2397
  }
2387
2398
  else {
2388
- hooks[prop] = (...args) => {
2389
- let ret = pack.hooks[prop].apply(hooks, args);
2399
+ hooks[hooksKey] = (...args) => {
2400
+ let ret = hooksFunc.apply(hooks, args);
2390
2401
  if (ret === false) {
2391
2402
  ret = prevHook.apply(hooks, args);
2392
2403
  }