ai-read-over-mobile 0.0.13 → 0.0.14
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/components/demo/src/read-over.vue +34 -28
- package/dist/ai-read-over-mobile.common.js +2923 -41
- package/dist/ai-read-over-mobile.common.js.map +1 -1
- package/dist/ai-read-over-mobile.css +1 -1
- package/dist/ai-read-over-mobile.umd.js +2923 -41
- package/dist/ai-read-over-mobile.umd.js.map +1 -1
- package/dist/ai-read-over-mobile.umd.min.js +4 -4
- package/dist/ai-read-over-mobile.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -51,6 +51,7 @@ import ChatTools from "./chat-tools.vue";
|
|
|
51
51
|
import '../static/iconfont/iconfont.css';
|
|
52
52
|
import katex from 'katex';
|
|
53
53
|
import 'katex/dist/katex.min.css';
|
|
54
|
+
import 'katex/contrib/mhchem/mhchem.js';
|
|
54
55
|
|
|
55
56
|
export default {
|
|
56
57
|
name: 'ReadOver',
|
|
@@ -90,6 +91,11 @@ export default {
|
|
|
90
91
|
},
|
|
91
92
|
renderFormulas(text) {
|
|
92
93
|
if (!text) return '';
|
|
94
|
+
text = text.replace(/>/g, '>')
|
|
95
|
+
.replace(/</g, '<')
|
|
96
|
+
.replace(/&/g, '&')
|
|
97
|
+
.replace(/"/g, '"')
|
|
98
|
+
.replace(/'/g, "'");
|
|
93
99
|
// 如果整个文本包含 LaTeX 命令且没有定界符,整体包裹
|
|
94
100
|
const hasDelimiter = /\$|\\\(|\\\[/.test(text);
|
|
95
101
|
if (!hasDelimiter) {
|
|
@@ -100,44 +106,44 @@ export default {
|
|
|
100
106
|
}
|
|
101
107
|
const { renderToString } = katex;
|
|
102
108
|
return text
|
|
103
|
-
// 块级公式
|
|
104
|
-
.replace(/\$\$(
|
|
109
|
+
// $$ ... $$ 块级公式
|
|
110
|
+
.replace(/\$\$([\s\S]*?)\$\$/gs, function (_, formula) {
|
|
105
111
|
try {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
} catch (
|
|
109
|
-
console.error('
|
|
110
|
-
return
|
|
112
|
+
const trimmedFormula = formula.trim()
|
|
113
|
+
return renderToString(trimmedFormula, { displayMode: true });
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error('Error rendering block formula:', error);
|
|
116
|
+
return _;
|
|
111
117
|
}
|
|
112
118
|
})
|
|
113
|
-
// 行内公式
|
|
114
|
-
.replace(
|
|
119
|
+
// \(...\) 行内公式
|
|
120
|
+
.replace(/\\\((.*?)\\\)/gs, function (_, formula) {
|
|
115
121
|
try {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
} catch (
|
|
119
|
-
console.error('
|
|
120
|
-
return
|
|
122
|
+
const trimmedFormula = formula.trim()
|
|
123
|
+
return renderToString(trimmedFormula, { displayMode: false });
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error('Error rendering inline formula:', error);
|
|
126
|
+
return _;
|
|
121
127
|
}
|
|
122
128
|
})
|
|
123
|
-
//
|
|
124
|
-
.replace(/\\\(
|
|
129
|
+
// \[...\] 块级公式
|
|
130
|
+
.replace(/\\\[(.*?)\\\]/gs, function (_, formula) {
|
|
125
131
|
try {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
} catch (
|
|
129
|
-
console.error('
|
|
130
|
-
return
|
|
132
|
+
const trimmedFormula = formula.trim()
|
|
133
|
+
return renderToString(trimmedFormula, { displayMode: true });
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error('Error rendering block formula:', error);
|
|
136
|
+
return _;
|
|
131
137
|
}
|
|
132
138
|
})
|
|
133
|
-
//
|
|
134
|
-
.replace(
|
|
139
|
+
// $...$ 行内公式
|
|
140
|
+
.replace(/\$(.+?)\$/gs, function (_, formula) {
|
|
135
141
|
try {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
} catch (
|
|
139
|
-
console.error('
|
|
140
|
-
return
|
|
142
|
+
const trimmedFormula = formula.trim()
|
|
143
|
+
return renderToString(trimmedFormula, { displayMode: false });
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error('Error rendering inline formula with $...$:', error);
|
|
146
|
+
return _;
|
|
141
147
|
}
|
|
142
148
|
});
|
|
143
149
|
},
|