ai-read-over-mobile 0.0.12 → 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 +36 -25
- package/dist/ai-read-over-mobile.common.js +2923 -35
- 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 -35
- 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,49 +91,59 @@ export default {
|
|
|
90
91
|
},
|
|
91
92
|
renderFormulas(text) {
|
|
92
93
|
if (!text) return '';
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
text = text.replace(/>/g, '>')
|
|
95
|
+
.replace(/</g, '<')
|
|
96
|
+
.replace(/&/g, '&')
|
|
97
|
+
.replace(/"/g, '"')
|
|
98
|
+
.replace(/'/g, "'");
|
|
99
|
+
// 如果整个文本包含 LaTeX 命令且没有定界符,整体包裹
|
|
100
|
+
const hasDelimiter = /\$|\\\(|\\\[/.test(text);
|
|
101
|
+
if (!hasDelimiter) {
|
|
102
|
+
text = text.replace(
|
|
103
|
+
/(\\(?:frac|sqrt|sum|int|cdot|times|geq|leq|neq|pm|div|alpha|beta|gamma|theta|pi|sigma|omega|infty|log|sin|cos|tan|left|right|overline|hat|vec|bar|lim|in|notin|supset|subseteq|ln|Gamma|to)(?:\{[^{}]*(?:\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}[^{}]*)*\}|[^\s{},。?!、;:\u4e00-\u9fa5])*)/g,
|
|
104
|
+
(match) => `\\(${match}\\)`
|
|
105
|
+
);
|
|
97
106
|
}
|
|
98
|
-
const {renderToString} = katex;
|
|
107
|
+
const { renderToString } = katex;
|
|
99
108
|
return text
|
|
100
|
-
|
|
109
|
+
// $$ ... $$ 块级公式
|
|
110
|
+
.replace(/\$\$([\s\S]*?)\$\$/gs, function (_, formula) {
|
|
101
111
|
try {
|
|
102
|
-
|
|
103
|
-
return renderToString(
|
|
112
|
+
const trimmedFormula = formula.trim()
|
|
113
|
+
return renderToString(trimmedFormula, { displayMode: true });
|
|
104
114
|
} catch (error) {
|
|
105
115
|
console.error('Error rendering block formula:', error);
|
|
106
|
-
return
|
|
116
|
+
return _;
|
|
107
117
|
}
|
|
108
118
|
})
|
|
109
|
-
|
|
110
|
-
|
|
119
|
+
// \(...\) 行内公式
|
|
120
|
+
.replace(/\\\((.*?)\\\)/gs, function (_, formula) {
|
|
111
121
|
try {
|
|
112
|
-
|
|
113
|
-
return renderToString(
|
|
122
|
+
const trimmedFormula = formula.trim()
|
|
123
|
+
return renderToString(trimmedFormula, { displayMode: false });
|
|
114
124
|
} catch (error) {
|
|
115
125
|
console.error('Error rendering inline formula:', error);
|
|
116
|
-
return
|
|
126
|
+
return _;
|
|
117
127
|
}
|
|
118
128
|
})
|
|
119
|
-
|
|
129
|
+
// \[...\] 块级公式
|
|
130
|
+
.replace(/\\\[(.*?)\\\]/gs, function (_, formula) {
|
|
120
131
|
try {
|
|
121
|
-
|
|
122
|
-
return renderToString(
|
|
132
|
+
const trimmedFormula = formula.trim()
|
|
133
|
+
return renderToString(trimmedFormula, { displayMode: true });
|
|
123
134
|
} catch (error) {
|
|
124
|
-
console.error('Error rendering
|
|
125
|
-
return
|
|
135
|
+
console.error('Error rendering block formula:', error);
|
|
136
|
+
return _;
|
|
126
137
|
}
|
|
127
138
|
})
|
|
128
|
-
|
|
129
|
-
|
|
139
|
+
// $...$ 行内公式
|
|
140
|
+
.replace(/\$(.+?)\$/gs, function (_, formula) {
|
|
130
141
|
try {
|
|
131
|
-
|
|
132
|
-
return renderToString(
|
|
142
|
+
const trimmedFormula = formula.trim()
|
|
143
|
+
return renderToString(trimmedFormula, { displayMode: false });
|
|
133
144
|
} catch (error) {
|
|
134
|
-
console.error('Error rendering
|
|
135
|
-
return
|
|
145
|
+
console.error('Error rendering inline formula with $...$:', error);
|
|
146
|
+
return _;
|
|
136
147
|
}
|
|
137
148
|
});
|
|
138
149
|
},
|