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