@ai-react-markdown/core 1.2.6 → 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 +15 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1669,29 +1669,24 @@ function escapeLatexPipes(text) {
|
|
|
1669
1669
|
return match;
|
|
1670
1670
|
});
|
|
1671
1671
|
}
|
|
1672
|
-
function
|
|
1672
|
+
function findUnclosedDelimiterStart(text, mode) {
|
|
1673
1673
|
let unclosedStart = -1;
|
|
1674
1674
|
let i = 0;
|
|
1675
1675
|
while (i < text.length) {
|
|
1676
1676
|
if (text[i] === "$" && i + 1 < text.length && text[i + 1] === "$") {
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
unclosedStart = -1;
|
|
1682
|
-
i += 2;
|
|
1683
|
-
}
|
|
1684
|
-
} else if (text[i] === "$" && (i === 0 || text[i - 1] !== "\\") && (i + 1 >= text.length || text[i + 1] !== "$")) {
|
|
1685
|
-
if (unclosedStart === -1) {
|
|
1686
|
-
unclosedStart = i;
|
|
1687
|
-
} else {
|
|
1688
|
-
unclosedStart = -1;
|
|
1689
|
-
}
|
|
1677
|
+
unclosedStart = unclosedStart === -1 ? i : -1;
|
|
1678
|
+
i += 2;
|
|
1679
|
+
} else if (mode === "both" && text[i] === "$" && (i === 0 || text[i - 1] !== "\\") && (i + 1 >= text.length || text[i + 1] !== "$")) {
|
|
1680
|
+
unclosedStart = unclosedStart === -1 ? i : -1;
|
|
1690
1681
|
i += 1;
|
|
1691
1682
|
} else {
|
|
1692
1683
|
i += 1;
|
|
1693
1684
|
}
|
|
1694
1685
|
}
|
|
1686
|
+
return unclosedStart;
|
|
1687
|
+
}
|
|
1688
|
+
function escapeLatexPipesInUnclosed(text) {
|
|
1689
|
+
const unclosedStart = findUnclosedDelimiterStart(text, "both");
|
|
1695
1690
|
if (unclosedStart === -1) return text;
|
|
1696
1691
|
const before = text.substring(0, unclosedStart);
|
|
1697
1692
|
const delimLen = text[unclosedStart + 1] === "$" ? 2 : 1;
|
|
@@ -1699,6 +1694,11 @@ function escapeLatexPipesInUnclosed(text) {
|
|
|
1699
1694
|
const tail = text.substring(unclosedStart + delimLen);
|
|
1700
1695
|
return before + delim + replaceUnescapedPipes(tail);
|
|
1701
1696
|
}
|
|
1697
|
+
function truncateUnclosedLatexBlock(text) {
|
|
1698
|
+
const unclosedStart = findUnclosedDelimiterStart(text, "double-only");
|
|
1699
|
+
if (unclosedStart === -1) return text;
|
|
1700
|
+
return text.substring(0, unclosedStart).trimEnd();
|
|
1701
|
+
}
|
|
1702
1702
|
function escapeTextUnderscores(text) {
|
|
1703
1703
|
return text.replaceAll(ESCAPE_TEXT_UNDERSCORES_REGEX, (_match, textContent) => {
|
|
1704
1704
|
const escapedTextContent = textContent.replaceAll(/(?<!\\)_/g, "\\_");
|
|
@@ -1721,6 +1721,7 @@ function preprocessLaTeX(str) {
|
|
|
1721
1721
|
text = escapeLatexPipesInUnclosed(text);
|
|
1722
1722
|
text = escapeTextUnderscores(text);
|
|
1723
1723
|
text = convertSingleToDoubleDollar(text);
|
|
1724
|
+
text = truncateUnclosedLatexBlock(text);
|
|
1724
1725
|
return text;
|
|
1725
1726
|
});
|
|
1726
1727
|
return result.join("");
|