acsi-core 0.9.2 → 0.9.3

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.
@@ -7,8 +7,13 @@ import { useDispatch, useSelector } from 'react-redux';
7
7
  import { Link } from 'react-router-dom';
8
8
  import { FormGroup, Input, Label, Modal, ModalHeader, ModalBody, ModalFooter, Tooltip, Row, Col, Button, Pagination, PaginationItem, PaginationLink } from 'reactstrap';
9
9
  import ReactSelect, { components } from 'react-select';
10
+ import ReactMarkdown from 'react-markdown';
11
+ import remarkMath from 'remark-math';
12
+ import remarkGfm from 'remark-gfm';
13
+ import rehypeKatex from 'rehype-katex';
14
+ import remarkRehype from 'remark-rehype';
15
+ import rehypeRaw from 'rehype-raw';
10
16
  import 'katex/dist/katex.min.css';
11
- import renderMathInElement from 'katex/contrib/auto-render';
12
17
  import Cookies from 'js-cookie';
13
18
  export { default as Cookies } from 'js-cookie';
14
19
  import moment from 'moment';
@@ -1662,72 +1667,71 @@ var CoreTooltip = function CoreTooltip(_ref) {
1662
1667
  }, content));
1663
1668
  };
1664
1669
 
1670
+ var LatexExtractor = /*#__PURE__*/function () {
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
+ });
1696
+ };
1697
+ return LatexExtractor;
1698
+ }();
1699
+
1700
+ var _excluded$3 = ["node"];
1665
1701
  var MarkdownLatexRender = function MarkdownLatexRender(_ref) {
1666
1702
  var content = _ref.content;
1667
- var displayRef = React.useRef(null);
1668
- var processedText = content.replace(/(.*)(?:\s*(.*))?(?=\n\n|$)/, function (_match, prefix, equation) {
1669
- if (equation) {
1670
- var trimmedEquation = equation.trim();
1671
- if (trimmedEquation.startsWith("\\(") && trimmedEquation.endsWith("\\)")) {
1672
- return "" + prefix + equation;
1673
- } else {
1674
- return prefix + "\n\\(" + equation + "\\)";
1675
- }
1676
- } else {
1677
- var latexStart = -1;
1678
- if (content.includes("_")) {
1679
- latexStart = content.search(/[a-zA-Z]_/);
1680
- } else if (content.includes("^")) {
1681
- latexStart = content.search(/[a-zA-Z]\^/);
1682
- } else if (content.includes("\\")) {
1683
- latexStart = content.search(/\\/);
1684
- }
1685
- if (latexStart !== -1) {
1686
- var _prefix = content.substring(0, latexStart);
1687
- var _equation = content.substring(latexStart);
1688
- return _prefix + "\\(" + _equation + "\\)";
1689
- } else {
1690
- return content;
1691
- }
1692
- }
1693
- });
1694
- useEffect(function () {
1695
- if (displayRef.current) {
1696
- try {
1697
- displayRef.current.innerHTML = processedText;
1698
- if (process.env.NODE_ENV === 'development') {
1699
- console.log('Original Content:', content);
1700
- console.log('Processed Content:', processedText);
1701
- }
1702
- renderMathInElement(displayRef.current, {
1703
- delimiters: [{
1704
- left: "$$",
1705
- right: "$$",
1706
- display: true
1707
- }, {
1708
- left: "$",
1709
- right: "$",
1710
- display: false
1711
- }, {
1712
- left: "\\(",
1713
- right: "\\)",
1714
- display: false
1715
- }, {
1716
- left: "\\[",
1717
- right: "\\]",
1718
- display: true
1719
- }]
1720
- });
1721
- } catch (error) {
1722
- console.error("Error rendering math:", error);
1703
+ var updatedMarkdown = formatContent(content);
1704
+ return React.createElement("span", null, React.createElement(ReactMarkdown, {
1705
+ remarkPlugins: [remarkMath, remarkGfm, remarkRehype],
1706
+ rehypePlugins: [rehypeKatex, rehypeRaw],
1707
+ components: {
1708
+ p: function p(_ref2) {
1709
+ var props = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
1710
+ return React.createElement("span", Object.assign({}, props));
1723
1711
  }
1724
1712
  }
1725
- }, [content]);
1726
- return React.createElement("div", {
1727
- ref: displayRef,
1728
- className: "equation-support"
1729
- });
1713
+ }, updatedMarkdown));
1730
1714
  };
1715
+ function formatContent(content) {
1716
+ var lines = content.split("\n");
1717
+ var result = [];
1718
+ var i = 0;
1719
+ while (i < lines.length) {
1720
+ 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);
1727
+ i++;
1728
+ continue;
1729
+ }
1730
+ result.push(line);
1731
+ i++;
1732
+ }
1733
+ return result.join("\n");
1734
+ }
1731
1735
 
1732
1736
  var CookieService = /*#__PURE__*/function () {
1733
1737
  function CookieService() {}
@@ -3324,7 +3328,7 @@ var CustomOption = function CustomOption(props) {
3324
3328
  }, props.data.label));
3325
3329
  };
3326
3330
 
3327
- var _excluded$3 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3331
+ var _excluded$4 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3328
3332
  var CustomSelect = function CustomSelect(_ref) {
3329
3333
  var isDefault = _ref.isDefault,
3330
3334
  options = _ref.options,
@@ -3332,7 +3336,7 @@ var CustomSelect = function CustomSelect(_ref) {
3332
3336
  scrollBottom = _ref.scrollBottom,
3333
3337
  value = _ref.value,
3334
3338
  isMulti = _ref.isMulti,
3335
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
3339
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
3336
3340
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3337
3341
  return value.includes(i.value);
3338
3342
  }) : isMulti ? options === null || options === void 0 ? void 0 : options.filter(function (i) {
@@ -3359,7 +3363,7 @@ var CustomSelect = function CustomSelect(_ref) {
3359
3363
  }, rest));
3360
3364
  };
3361
3365
 
3362
- var _excluded$4 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3366
+ var _excluded$5 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3363
3367
  var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3364
3368
  var isDefault = _ref.isDefault,
3365
3369
  options = _ref.options,
@@ -3367,7 +3371,7 @@ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3367
3371
  scrollBottom = _ref.scrollBottom,
3368
3372
  value = _ref.value,
3369
3373
  isMulti = _ref.isMulti,
3370
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
3374
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
3371
3375
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3372
3376
  return value.includes(i.value);
3373
3377
  }) : isMulti ? options.filter(function (i) {
@@ -3394,14 +3398,14 @@ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3394
3398
  }, rest));
3395
3399
  };
3396
3400
 
3397
- var _excluded$5 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3401
+ var _excluded$6 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3398
3402
  var CustomCreatable = function CustomCreatable(_ref) {
3399
3403
  var options = _ref.options,
3400
3404
  isDisabled = _ref.isDisabled,
3401
3405
  scrollBottom = _ref.scrollBottom,
3402
3406
  value = _ref.value,
3403
3407
  isMulti = _ref.isMulti,
3404
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
3408
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
3405
3409
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
3406
3410
  return value.includes(i.value);
3407
3411
  }) : isMulti ? options.filter(function (i) {
@@ -3428,7 +3432,7 @@ var CustomCreatable = function CustomCreatable(_ref) {
3428
3432
  }, rest));
3429
3433
  };
3430
3434
 
3431
- var _excluded$6 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3435
+ var _excluded$7 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3432
3436
  var CustomSelectOption = function CustomSelectOption(_ref) {
3433
3437
  var defaultValue = _ref.defaultValue,
3434
3438
  options = _ref.options,
@@ -3436,7 +3440,7 @@ var CustomSelectOption = function CustomSelectOption(_ref) {
3436
3440
  scrollBottom = _ref.scrollBottom,
3437
3441
  value = _ref.value,
3438
3442
  isMulti = _ref.isMulti,
3439
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
3443
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
3440
3444
  var initialValues = defaultValue !== null && typeof defaultValue !== "undefined" ? options.find(function (option) {
3441
3445
  return option.value === defaultValue;
3442
3446
  }) || null : null;