acsi-core 0.9.3 → 0.9.5
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.js +37 -30
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +37 -30
- package/dist/index.modern.js.map +1 -1
- package/dist/utils/latexExtractor.d.ts +4 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1670,33 +1670,43 @@ var CoreTooltip = function CoreTooltip(_ref) {
|
|
|
1670
1670
|
|
|
1671
1671
|
var LatexExtractor = /*#__PURE__*/function () {
|
|
1672
1672
|
function LatexExtractor() {}
|
|
1673
|
-
LatexExtractor.
|
|
1674
|
-
var
|
|
1675
|
-
var
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
return matches.map(function (match) {
|
|
1688
|
-
return match.trim();
|
|
1689
|
-
});
|
|
1690
|
-
};
|
|
1691
|
-
LatexExtractor.extractDisplayMath = function extractDisplayMath(content) {
|
|
1692
|
-
var displayMathRegex = /\\\[[^\]]+\\\]/g;
|
|
1693
|
-
var matches = content.match(displayMathRegex) || [];
|
|
1694
|
-
return matches.map(function (match) {
|
|
1695
|
-
return match.trim();
|
|
1696
|
-
});
|
|
1673
|
+
LatexExtractor.ApplyLatexFormat = function ApplyLatexFormat(content) {
|
|
1674
|
+
var allComponents = LatexExtractor.extractAllLatexUltimate(content);
|
|
1675
|
+
var multiLineFormulas = LatexExtractor.extractMultiLineFormulas(content);
|
|
1676
|
+
var foundLatexStr = multiLineFormulas[0] || "";
|
|
1677
|
+
if (foundLatexStr && foundLatexStr !== "" && content.includes(foundLatexStr)) {
|
|
1678
|
+
var firstPosition = content.indexOf(allComponents[0]);
|
|
1679
|
+
if (firstPosition > 0) {
|
|
1680
|
+
var textPart = content.slice(0, firstPosition).trim();
|
|
1681
|
+
var latexPart = content.slice(firstPosition).trim();
|
|
1682
|
+
return textPart + (" $$" + latexPart + "$$");
|
|
1683
|
+
}
|
|
1684
|
+
return content.replace(foundLatexStr, "$$" + foundLatexStr + "$$");
|
|
1685
|
+
}
|
|
1686
|
+
return content;
|
|
1697
1687
|
};
|
|
1698
1688
|
return LatexExtractor;
|
|
1699
1689
|
}();
|
|
1690
|
+
LatexExtractor.extractAllLatexUltimate = function (content) {
|
|
1691
|
+
var latexRegex = /(\\[a-zA-Z]+\s*\{[^}]*\}(?:\s*\{[^}]*\})*|\\[a-zA-Z]+|\\[a-zA-Z]+\s*[^\\\s\{]+|[a-zA-Z]+\^{[^}]*}|[a-zA-Z]+\_{[^}]*}|\$[^$]+\$|\\\([^)]+\\\)|\\\[[^\]]+\\\]|\\[a-zA-Z]+\d*|(?:\\[a-zA-Z]+\s*)+[^\\]*(?=\\\\|\.|$))/g;
|
|
1692
|
+
var matches = content.match(latexRegex) || [];
|
|
1693
|
+
return matches.filter(function (match) {
|
|
1694
|
+
return match.length > 1 && !match.match(/^[,\s\.]*$/) && (match.includes("\\") || match.includes("^{") || match.includes("_{") || match.includes("$") || !!match.match(/[a-zA-Z]\s*[=+\-*/]\s*[a-zA-Z0-9]/));
|
|
1695
|
+
});
|
|
1696
|
+
};
|
|
1697
|
+
LatexExtractor.extractMultiLineFormulas = function (content) {
|
|
1698
|
+
var formulas = content.split(/\\\\/);
|
|
1699
|
+
return formulas.map(function (formula) {
|
|
1700
|
+
var cleaned = formula.trim();
|
|
1701
|
+
cleaned = cleaned.replace(/\.$/, "");
|
|
1702
|
+
return cleaned;
|
|
1703
|
+
}).filter(function (formula) {
|
|
1704
|
+
return formula.length > 0 && LatexExtractor.isMathFormula(formula);
|
|
1705
|
+
});
|
|
1706
|
+
};
|
|
1707
|
+
LatexExtractor.isMathFormula = function (text) {
|
|
1708
|
+
return !!text && (text.includes("=") || text.includes("\\") || text.includes("^{") || text.includes("_{") || !!text.match(/[a-zA-Z]\s*[=+\-*/]\s*[a-zA-Z0-9]/));
|
|
1709
|
+
};
|
|
1700
1710
|
|
|
1701
1711
|
var _excluded$3 = ["node"];
|
|
1702
1712
|
var MarkdownLatexRender = function MarkdownLatexRender(_ref) {
|
|
@@ -1719,12 +1729,9 @@ function formatContent(content) {
|
|
|
1719
1729
|
var i = 0;
|
|
1720
1730
|
while (i < lines.length) {
|
|
1721
1731
|
var line = lines[i];
|
|
1722
|
-
var
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
});
|
|
1726
|
-
if (newline !== line) {
|
|
1727
|
-
result.push(newline);
|
|
1732
|
+
var appliedLatexFormat = LatexExtractor.ApplyLatexFormat(line);
|
|
1733
|
+
if (appliedLatexFormat !== line) {
|
|
1734
|
+
result.push(appliedLatexFormat);
|
|
1728
1735
|
i++;
|
|
1729
1736
|
continue;
|
|
1730
1737
|
}
|