marked 4.1.1 → 4.2.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.esm.js CHANGED
@@ -939,22 +939,24 @@ class Tokenizer {
939
939
  // Remove extra characters. *a*** -> *a*
940
940
  rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
941
941
 
942
+ const raw = src.slice(0, lLength + match.index + (match[0].length - rDelim.length) + rLength);
943
+
942
944
  // Create `em` if smallest delimiter has odd char count. *a***
943
945
  if (Math.min(lLength, rLength) % 2) {
944
- const text = src.slice(1, lLength + match.index + rLength);
946
+ const text = raw.slice(1, -1);
945
947
  return {
946
948
  type: 'em',
947
- raw: src.slice(0, lLength + match.index + rLength + 1),
949
+ raw,
948
950
  text,
949
951
  tokens: this.lexer.inlineTokens(text)
950
952
  };
951
953
  }
952
954
 
953
955
  // Create 'strong' if smallest delimiter has even char count. **a***
954
- const text = src.slice(2, lLength + match.index + rLength - 1);
956
+ const text = raw.slice(2, -2);
955
957
  return {
956
958
  type: 'strong',
957
- raw: src.slice(0, lLength + match.index + rLength + 1),
959
+ raw,
958
960
  text,
959
961
  tokens: this.lexer.inlineTokens(text)
960
962
  };
@@ -1249,9 +1251,9 @@ const inline = {
1249
1251
  emStrong: {
1250
1252
  lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
1251
1253
  // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
1252
- // () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
1253
- rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[^*]+(?=[^*])|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
1254
- rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
1254
+ // () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
1255
+ rDelimAst: /^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,
1256
+ rDelimUnd: /^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
1255
1257
  },
1256
1258
  code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
1257
1259
  br: /^( {2,}|\\)\n(?!\s*$)/,
@@ -1267,7 +1269,9 @@ inline.punctuation = edit(inline.punctuation).replace(/punctuation/g, inline._pu
1267
1269
 
1268
1270
  // sequences em should skip over [title](link), `code`, <html>
1269
1271
  inline.blockSkip = /\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;
1270
- inline.escapedEmSt = /\\\*|\\_/g;
1272
+ // lookbehind is not available on Safari as of version 16
1273
+ // inline.escapedEmSt = /(?<=(?:^|[^\\)(?:\\[^])*)\\[*_]/g;
1274
+ inline.escapedEmSt = /(?:^|[^\\])(?:\\\\)*\\[*_]/g;
1271
1275
 
1272
1276
  inline._comment = edit(block._comment).replace('(?:-->|$)', '-->').getRegex();
1273
1277
 
@@ -1729,7 +1733,8 @@ class Lexer {
1729
1733
 
1730
1734
  // Mask out escaped em & strong delimiters
1731
1735
  while ((match = this.tokenizer.rules.inline.escapedEmSt.exec(maskedSrc)) != null) {
1732
- maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex);
1736
+ maskedSrc = maskedSrc.slice(0, match.index + match[0].length - 2) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex);
1737
+ this.tokenizer.rules.inline.escapedEmSt.lastIndex--;
1733
1738
  }
1734
1739
 
1735
1740
  while (src) {