@lobehub/ui 1.144.4 → 1.144.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/es/Markdown/index.d.ts +1 -0
- package/es/Markdown/index.js +11 -4
- package/es/Markdown/utils.d.ts +3 -0
- package/es/Markdown/utils.js +28 -0
- package/package.json +2 -2
package/es/Markdown/index.d.ts
CHANGED
package/es/Markdown/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["children", "className", "style", "fullFeaturedCodeBlock", "onDoubleClick", "enableImageGallery", "componentProps", "allowHtml", "fontSize", "headerMultiple", "marginMultiple", "variant", "lineHeight"];
|
|
5
|
+
var _excluded = ["children", "className", "style", "fullFeaturedCodeBlock", "onDoubleClick", "enableLatex", "enableImageGallery", "componentProps", "allowHtml", "fontSize", "headerMultiple", "marginMultiple", "variant", "lineHeight"];
|
|
6
6
|
import { memo, useMemo } from 'react';
|
|
7
7
|
import ReactMarkdown from 'react-markdown';
|
|
8
8
|
import rehypeKatex from 'rehype-katex';
|
|
@@ -17,6 +17,7 @@ import Video from "../mdx/Video";
|
|
|
17
17
|
import { CodeFullFeatured, CodeLite } from "./CodeBlock";
|
|
18
18
|
import { useStyles as useMarkdownStyles } from "./markdown.style";
|
|
19
19
|
import { useStyles } from "./style";
|
|
20
|
+
import { escapeBrackets, escapeDollarNumber, escapeMhchem } from "./utils";
|
|
20
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
22
|
var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
22
23
|
var children = _ref.children,
|
|
@@ -24,6 +25,8 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
24
25
|
style = _ref.style,
|
|
25
26
|
fullFeaturedCodeBlock = _ref.fullFeaturedCodeBlock,
|
|
26
27
|
onDoubleClick = _ref.onDoubleClick,
|
|
28
|
+
_ref$enableLatex = _ref.enableLatex,
|
|
29
|
+
enableLatex = _ref$enableLatex === void 0 ? true : _ref$enableLatex,
|
|
27
30
|
_ref$enableImageGalle = _ref.enableImageGallery,
|
|
28
31
|
enableImageGallery = _ref$enableImageGalle === void 0 ? true : _ref$enableImageGalle,
|
|
29
32
|
componentProps = _ref.componentProps,
|
|
@@ -50,6 +53,10 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
50
53
|
}),
|
|
51
54
|
mdStyles = _useMarkdownStyles.styles;
|
|
52
55
|
var isChatMode = variant === 'chat';
|
|
56
|
+
var escapedContent = useMemo(function () {
|
|
57
|
+
if (!enableLatex) return children;
|
|
58
|
+
return escapeMhchem(escapeBrackets(escapeDollarNumber(children)));
|
|
59
|
+
}, [children, enableLatex]);
|
|
53
60
|
var components = useMemo(function () {
|
|
54
61
|
return {
|
|
55
62
|
a: function a(props) {
|
|
@@ -73,10 +80,10 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
73
80
|
};
|
|
74
81
|
}, [componentProps, enableImageGallery, fullFeaturedCodeBlock]);
|
|
75
82
|
var rehypePlugins = useMemo(function () {
|
|
76
|
-
return [allowHtml && rehypeRaw, rehypeKatex].filter(Boolean);
|
|
83
|
+
return [allowHtml && rehypeRaw, enableLatex && rehypeKatex].filter(Boolean);
|
|
77
84
|
}, [allowHtml]);
|
|
78
85
|
var remarkPlugins = useMemo(function () {
|
|
79
|
-
return [remarkGfm, remarkMath, isChatMode && remarkBreaks].filter(Boolean);
|
|
86
|
+
return [remarkGfm, enableLatex && remarkMath, isChatMode && remarkBreaks].filter(Boolean);
|
|
80
87
|
}, [isChatMode]);
|
|
81
88
|
return /*#__PURE__*/_jsx("article", {
|
|
82
89
|
className: cx(styles.root, className),
|
|
@@ -91,7 +98,7 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
|
|
|
91
98
|
rehypePlugins: rehypePlugins,
|
|
92
99
|
remarkPlugins: remarkPlugins
|
|
93
100
|
}, rest), {}, {
|
|
94
|
-
children:
|
|
101
|
+
children: escapedContent
|
|
95
102
|
}))
|
|
96
103
|
})
|
|
97
104
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function escapeDollarNumber(text) {
|
|
2
|
+
var escapedText = '';
|
|
3
|
+
for (var i = 0; i < text.length; i += 1) {
|
|
4
|
+
var char = text[i];
|
|
5
|
+
var nextChar = text[i + 1] || ' ';
|
|
6
|
+
if (char === '$' && nextChar >= '0' && nextChar <= '9') {
|
|
7
|
+
char = '\\$';
|
|
8
|
+
}
|
|
9
|
+
escapedText += char;
|
|
10
|
+
}
|
|
11
|
+
return escapedText;
|
|
12
|
+
}
|
|
13
|
+
export function escapeBrackets(text) {
|
|
14
|
+
var pattern = /(```[\S\s]*?```|`.*?`)|\\\[([\S\s]*?[^\\])\\]|\\\((.*?)\\\)/g;
|
|
15
|
+
return text.replaceAll(pattern, function (match, codeBlock, squareBracket, roundBracket) {
|
|
16
|
+
if (codeBlock) {
|
|
17
|
+
return codeBlock;
|
|
18
|
+
} else if (squareBracket) {
|
|
19
|
+
return "$$".concat(squareBracket, "$$");
|
|
20
|
+
} else if (roundBracket) {
|
|
21
|
+
return "$".concat(roundBracket, "$");
|
|
22
|
+
}
|
|
23
|
+
return match;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export function escapeMhchem(text) {
|
|
27
|
+
return text.replaceAll('$\\ce{', '$\\\\ce{').replaceAll('$\\pu{', '$\\\\pu{');
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/ui",
|
|
3
|
-
"version": "1.144.
|
|
3
|
+
"version": "1.144.5",
|
|
4
4
|
"description": "Lobe UI is an open-source UI component library for building AIGC web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lobehub",
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
"@types/react": "18.2.40",
|
|
140
140
|
"@types/react-dom": "^18.3.0",
|
|
141
141
|
"@types/uuid": "^9.0.8",
|
|
142
|
-
"@vitest/coverage-v8": "
|
|
142
|
+
"@vitest/coverage-v8": "~1.2.2",
|
|
143
143
|
"antd-style": "^3.6.2",
|
|
144
144
|
"babel-plugin-antd-style": "^1.0.4",
|
|
145
145
|
"commitlint": "^19.3.0",
|