acsi-core 0.9.3 → 0.9.4

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