@ai-react-markdown/core 1.2.5 → 1.2.6
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 +55 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +55 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1533,11 +1533,20 @@ var AIMarkdownRenderStateProvider = ({
|
|
|
1533
1533
|
var context_default = AIMarkdownRenderStateProvider;
|
|
1534
1534
|
|
|
1535
1535
|
// src/preprocessors/latex.ts
|
|
1536
|
+
function getRepeatedMarkerLength(content, start, marker) {
|
|
1537
|
+
let end = start;
|
|
1538
|
+
while (end < content.length && content[end] === marker) {
|
|
1539
|
+
end += 1;
|
|
1540
|
+
}
|
|
1541
|
+
return end - start;
|
|
1542
|
+
}
|
|
1536
1543
|
function splitByProtectedRegions(content) {
|
|
1537
1544
|
const segments = [];
|
|
1538
1545
|
let lastIndex = 0;
|
|
1539
1546
|
let inlineStart = -1;
|
|
1540
1547
|
let multilineStart = -1;
|
|
1548
|
+
let multilineFenceMarker = null;
|
|
1549
|
+
let multilineFenceLength = 0;
|
|
1541
1550
|
function pushProtected(start, end) {
|
|
1542
1551
|
if (start > lastIndex) {
|
|
1543
1552
|
segments.push({ text: content.substring(lastIndex, start), isCode: false });
|
|
@@ -1547,15 +1556,22 @@ function splitByProtectedRegions(content) {
|
|
|
1547
1556
|
}
|
|
1548
1557
|
for (let i = 0; i < content.length; i++) {
|
|
1549
1558
|
const char = content[i];
|
|
1550
|
-
|
|
1559
|
+
const fenceLength = char === "`" || char === "~" ? getRepeatedMarkerLength(content, i, char) : 0;
|
|
1560
|
+
if ((char === "`" || char === "~") && fenceLength >= 3) {
|
|
1551
1561
|
if (multilineStart === -1) {
|
|
1552
1562
|
inlineStart = -1;
|
|
1553
1563
|
multilineStart = i;
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1564
|
+
multilineFenceMarker = char;
|
|
1565
|
+
multilineFenceLength = fenceLength;
|
|
1566
|
+
i += fenceLength - 1;
|
|
1567
|
+
} else if (char === multilineFenceMarker && fenceLength >= multilineFenceLength) {
|
|
1568
|
+
pushProtected(multilineStart, i + fenceLength);
|
|
1557
1569
|
multilineStart = -1;
|
|
1558
|
-
|
|
1570
|
+
multilineFenceMarker = null;
|
|
1571
|
+
multilineFenceLength = 0;
|
|
1572
|
+
i += fenceLength - 1;
|
|
1573
|
+
} else {
|
|
1574
|
+
i += fenceLength - 1;
|
|
1559
1575
|
}
|
|
1560
1576
|
} else if (char === "`" && multilineStart === -1) {
|
|
1561
1577
|
if (inlineStart === -1) {
|
|
@@ -1575,6 +1591,9 @@ function splitByProtectedRegions(content) {
|
|
|
1575
1591
|
}
|
|
1576
1592
|
}
|
|
1577
1593
|
}
|
|
1594
|
+
if (multilineStart !== -1) {
|
|
1595
|
+
pushProtected(multilineStart, content.length);
|
|
1596
|
+
}
|
|
1578
1597
|
if (lastIndex < content.length) {
|
|
1579
1598
|
segments.push({ text: content.substring(lastIndex), isCode: false });
|
|
1580
1599
|
}
|
|
@@ -1650,6 +1669,36 @@ function escapeLatexPipes(text) {
|
|
|
1650
1669
|
return match;
|
|
1651
1670
|
});
|
|
1652
1671
|
}
|
|
1672
|
+
function escapeLatexPipesInUnclosed(text) {
|
|
1673
|
+
let unclosedStart = -1;
|
|
1674
|
+
let i = 0;
|
|
1675
|
+
while (i < text.length) {
|
|
1676
|
+
if (text[i] === "$" && i + 1 < text.length && text[i + 1] === "$") {
|
|
1677
|
+
if (unclosedStart === -1) {
|
|
1678
|
+
unclosedStart = i;
|
|
1679
|
+
i += 2;
|
|
1680
|
+
} else {
|
|
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
|
+
}
|
|
1690
|
+
i += 1;
|
|
1691
|
+
} else {
|
|
1692
|
+
i += 1;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
if (unclosedStart === -1) return text;
|
|
1696
|
+
const before = text.substring(0, unclosedStart);
|
|
1697
|
+
const delimLen = text[unclosedStart + 1] === "$" ? 2 : 1;
|
|
1698
|
+
const delim = text.substring(unclosedStart, unclosedStart + delimLen);
|
|
1699
|
+
const tail = text.substring(unclosedStart + delimLen);
|
|
1700
|
+
return before + delim + replaceUnescapedPipes(tail);
|
|
1701
|
+
}
|
|
1653
1702
|
function escapeTextUnderscores(text) {
|
|
1654
1703
|
return text.replaceAll(ESCAPE_TEXT_UNDERSCORES_REGEX, (_match, textContent) => {
|
|
1655
1704
|
const escapedTextContent = textContent.replaceAll(/(?<!\\)_/g, "\\_");
|
|
@@ -1669,6 +1718,7 @@ function preprocessLaTeX(str) {
|
|
|
1669
1718
|
text = escapeCurrencyDollarSigns(text);
|
|
1670
1719
|
text = convertLatexDelimiters(text);
|
|
1671
1720
|
text = escapeLatexPipes(text);
|
|
1721
|
+
text = escapeLatexPipesInUnclosed(text);
|
|
1672
1722
|
text = escapeTextUnderscores(text);
|
|
1673
1723
|
text = convertSingleToDoubleDollar(text);
|
|
1674
1724
|
return text;
|