@ai-react-markdown/core 1.2.7 → 1.2.8

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/dist/index.cjs CHANGED
@@ -1708,29 +1708,24 @@ function escapeLatexPipes(text) {
1708
1708
  return match;
1709
1709
  });
1710
1710
  }
1711
- function escapeLatexPipesInUnclosed(text) {
1711
+ function findUnclosedDelimiterStart(text, mode) {
1712
1712
  let unclosedStart = -1;
1713
1713
  let i = 0;
1714
1714
  while (i < text.length) {
1715
1715
  if (text[i] === "$" && i + 1 < text.length && text[i + 1] === "$") {
1716
- if (unclosedStart === -1) {
1717
- unclosedStart = i;
1718
- i += 2;
1719
- } else {
1720
- unclosedStart = -1;
1721
- i += 2;
1722
- }
1723
- } else if (text[i] === "$" && (i === 0 || text[i - 1] !== "\\") && (i + 1 >= text.length || text[i + 1] !== "$")) {
1724
- if (unclosedStart === -1) {
1725
- unclosedStart = i;
1726
- } else {
1727
- unclosedStart = -1;
1728
- }
1716
+ unclosedStart = unclosedStart === -1 ? i : -1;
1717
+ i += 2;
1718
+ } else if (mode === "both" && text[i] === "$" && (i === 0 || text[i - 1] !== "\\") && (i + 1 >= text.length || text[i + 1] !== "$")) {
1719
+ unclosedStart = unclosedStart === -1 ? i : -1;
1729
1720
  i += 1;
1730
1721
  } else {
1731
1722
  i += 1;
1732
1723
  }
1733
1724
  }
1725
+ return unclosedStart;
1726
+ }
1727
+ function escapeLatexPipesInUnclosed(text) {
1728
+ const unclosedStart = findUnclosedDelimiterStart(text, "both");
1734
1729
  if (unclosedStart === -1) return text;
1735
1730
  const before = text.substring(0, unclosedStart);
1736
1731
  const delimLen = text[unclosedStart + 1] === "$" ? 2 : 1;
@@ -1739,20 +1734,7 @@ function escapeLatexPipesInUnclosed(text) {
1739
1734
  return before + delim + replaceUnescapedPipes(tail);
1740
1735
  }
1741
1736
  function truncateUnclosedLatexBlock(text) {
1742
- let unclosedStart = -1;
1743
- let i = 0;
1744
- while (i < text.length) {
1745
- if (text[i] === "$" && i + 1 < text.length && text[i + 1] === "$") {
1746
- if (unclosedStart === -1) {
1747
- unclosedStart = i;
1748
- } else {
1749
- unclosedStart = -1;
1750
- }
1751
- i += 2;
1752
- } else {
1753
- i += 1;
1754
- }
1755
- }
1737
+ const unclosedStart = findUnclosedDelimiterStart(text, "double-only");
1756
1738
  if (unclosedStart === -1) return text;
1757
1739
  return text.substring(0, unclosedStart).trimEnd();
1758
1740
  }