@ai-react-markdown/core 1.2.6 → 1.2.7

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
@@ -1738,6 +1738,24 @@ function escapeLatexPipesInUnclosed(text) {
1738
1738
  const tail = text.substring(unclosedStart + delimLen);
1739
1739
  return before + delim + replaceUnescapedPipes(tail);
1740
1740
  }
1741
+ 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
+ }
1756
+ if (unclosedStart === -1) return text;
1757
+ return text.substring(0, unclosedStart).trimEnd();
1758
+ }
1741
1759
  function escapeTextUnderscores(text) {
1742
1760
  return text.replaceAll(ESCAPE_TEXT_UNDERSCORES_REGEX, (_match, textContent) => {
1743
1761
  const escapedTextContent = textContent.replaceAll(/(?<!\\)_/g, "\\_");
@@ -1760,6 +1778,7 @@ function preprocessLaTeX(str) {
1760
1778
  text = escapeLatexPipesInUnclosed(text);
1761
1779
  text = escapeTextUnderscores(text);
1762
1780
  text = convertSingleToDoubleDollar(text);
1781
+ text = truncateUnclosedLatexBlock(text);
1763
1782
  return text;
1764
1783
  });
1765
1784
  return result.join("");