@depup/markdown-it 15.0.1-depup.9 → 15.0.2-depup.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.
@@ -1,4 +1,4 @@
1
- /*! markdown-it 15.0.1 https://github.com/markdown-it/markdown-it @license MIT */
1
+ /*! markdown-it 15.0.2 https://github.com/markdown-it/markdown-it @license MIT */
2
2
  //#region \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
@@ -1696,6 +1696,14 @@ function replace(state) {
1696
1696
  var QUOTE_TEST_RE = /['"]/;
1697
1697
  var QUOTE_RE = /['"]/g;
1698
1698
  var APOSTROPHE = "’";
1699
+ var MAX_OPENERS = 1e3;
1700
+ function truncateStack(stack, heads, length) {
1701
+ while (stack.length > length) {
1702
+ const item = stack.pop();
1703
+ if (item.isSingleQuote) heads.single = item.prevSameQuoteIdx;
1704
+ else heads.double = item.prevSameQuoteIdx;
1705
+ }
1706
+ }
1699
1707
  function addReplacement(replacements, tokenIdx, pos, ch) {
1700
1708
  if (!replacements[tokenIdx]) replacements[tokenIdx] = [];
1701
1709
  replacements[tokenIdx].push({
@@ -1717,12 +1725,16 @@ function applyReplacements(str, replacements) {
1717
1725
  function process_inlines(tokens, state) {
1718
1726
  let j;
1719
1727
  const stack = [];
1728
+ const heads = {
1729
+ single: -1,
1730
+ double: -1
1731
+ };
1720
1732
  const replacements = {};
1721
1733
  for (let i = 0; i < tokens.length; i++) {
1722
1734
  const token = tokens[i];
1723
1735
  const thisLevel = tokens[i].level;
1724
1736
  for (j = stack.length - 1; j >= 0; j--) if (stack[j].level <= thisLevel) break;
1725
- stack.length = j + 1;
1737
+ truncateStack(stack, heads, j + 1);
1726
1738
  if (token.type !== "text") continue;
1727
1739
  const text = token.content;
1728
1740
  let pos = 0;
@@ -1774,11 +1786,10 @@ function process_inlines(tokens, state) {
1774
1786
  if (isSingle) addReplacement(replacements, i, t.index, APOSTROPHE);
1775
1787
  continue;
1776
1788
  }
1777
- if (canClose) for (j = stack.length - 1; j >= 0; j--) {
1778
- let item = stack[j];
1779
- if (stack[j].level < thisLevel) break;
1780
- if (item.single === isSingle && stack[j].level === thisLevel) {
1781
- item = stack[j];
1789
+ if (canClose) {
1790
+ j = isSingle ? heads.single : heads.double;
1791
+ if (j >= 0 && stack[j].level === thisLevel) {
1792
+ const item = stack[j];
1782
1793
  let openQuote;
1783
1794
  let closeQuote;
1784
1795
  if (isSingle) {
@@ -1789,18 +1800,23 @@ function process_inlines(tokens, state) {
1789
1800
  closeQuote = state.md.options.quotes[1];
1790
1801
  }
1791
1802
  addReplacement(replacements, i, t.index, closeQuote);
1792
- addReplacement(replacements, item.token, item.pos, openQuote);
1793
- stack.length = j;
1803
+ addReplacement(replacements, item.tokenIdx, item.contentPos, openQuote);
1804
+ truncateStack(stack, heads, j);
1794
1805
  continue OUTER;
1795
1806
  }
1796
1807
  }
1797
- if (canOpen) stack.push({
1798
- token: i,
1799
- pos: t.index,
1800
- single: isSingle,
1801
- level: thisLevel
1802
- });
1803
- else if (canClose && isSingle) addReplacement(replacements, i, t.index, APOSTROPHE);
1808
+ if (canOpen) {
1809
+ if (stack.length >= MAX_OPENERS) return;
1810
+ stack.push({
1811
+ tokenIdx: i,
1812
+ contentPos: t.index,
1813
+ isSingleQuote: isSingle,
1814
+ level: thisLevel,
1815
+ prevSameQuoteIdx: isSingle ? heads.single : heads.double
1816
+ });
1817
+ if (isSingle) heads.single = stack.length - 1;
1818
+ else heads.double = stack.length - 1;
1819
+ } else if (canClose && isSingle) addReplacement(replacements, i, t.index, APOSTROPHE);
1804
1820
  }
1805
1821
  }
1806
1822
  Object.keys(replacements).forEach(function(tokenIdx) {