ai-read-over-pro 0.0.17 → 0.0.18

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.
@@ -45,6 +45,7 @@
45
45
  import ChatTools from "./chat-tools.vue";
46
46
  import katex from 'katex';
47
47
  import 'katex/dist/katex.min.css';
48
+ import 'katex/contrib/mhchem/mhchem.js';
48
49
  export default {
49
50
  name: 'ReadOver',
50
51
  components: {
@@ -73,58 +74,63 @@ export default {
73
74
  this.$emit('on-noty-apply', this.analyzeData, this.exercisesData);
74
75
  },
75
76
  renderFormulas(text) {
76
- if (!text) return '';
77
- // 如果整个文本包含 LaTeX 命令且没有定界符,整体包裹
78
- const hasDelimiter = /\$|\\\(|\\\[/.test(text);
79
- if (!hasDelimiter) {
80
- text = text.replace(
81
- /(\\(?: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,
82
- (match) => `\\(${match}\\)`
83
- );
84
- }
85
- const { renderToString } = katex;
86
- return text
87
- // 块级公式 $$...$$
88
- .replace(/\$\$(.*?)\$\$/gs, (match, p1) => {
89
- try {
90
- return renderToString(p1, { displayMode: true, throwOnError:
91
- false });
92
- } catch (e) {
93
- console.error('Block formula error:', e);
94
- return match;
95
- }
96
- })
97
- // 行内公式 $...$
98
- .replace(/\$(.*?)\$/g, (match, p1) => {
99
- try {
100
- return renderToString(p1, { displayMode: false, throwOnError:
101
- false });
102
- } catch (e) {
103
- console.error('Inline formula error:', e);
104
- return match;
105
- }
106
- })
107
- // 行内公式 \( ... \)
108
- .replace(/\\\((.*?)\\\)/g, (match, p1) => {
109
- try {
110
- return renderToString(p1, { displayMode: false, throwOnError:
111
- false });
112
- } catch (e) {
113
- console.error('Inline formula error:', e);
114
- return match;
115
- }
116
- })
117
- // 块级公式 \[ ... \]
118
- .replace(/\\\[(.*?)\\\]/gs, (match, p1) => {
119
- try {
120
- return renderToString(p1, { displayMode: true, throwOnError:
121
- false });
122
- } catch (e) {
123
- console.error('Block formula error:', e);
124
- return match;
125
- }
126
- });
127
- },
77
+ if (!text) return '';
78
+ text = text.replace(/>/g, '>')
79
+ .replace(/&lt;/g, '<')
80
+ .replace(/&amp;/g, '&')
81
+ .replace(/&quot;/g, '"')
82
+ .replace(/&#39;/g, "'");
83
+ // 如果整个文本包含 LaTeX 命令且没有定界符,整体包裹
84
+ const hasDelimiter = /\$|\\\(|\\\[/.test(text);
85
+ if (!hasDelimiter) {
86
+ text = text.replace(
87
+ /(\\(?: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,
88
+ (match) => `\\(${match}\\)`
89
+ );
90
+ }
91
+ const { renderToString } = katex;
92
+ return text
93
+ // $$ ... $$ 块级公式
94
+ .replace(/\$\$([\s\S]*?)\$\$/gs, function (_, formula) {
95
+ try {
96
+ const trimmedFormula = formula.trim()
97
+ return renderToString(trimmedFormula, { displayMode: true });
98
+ } catch (error) {
99
+ console.error('Error rendering block formula:', error);
100
+ return _;
101
+ }
102
+ })
103
+ // \(...\) 行内公式
104
+ .replace(/\\\((.*?)\\\)/gs, function (_, formula) {
105
+ try {
106
+ const trimmedFormula = formula.trim()
107
+ return renderToString(trimmedFormula, { displayMode: false });
108
+ } catch (error) {
109
+ console.error('Error rendering inline formula:', error);
110
+ return _;
111
+ }
112
+ })
113
+ // \[...\] 块级公式
114
+ .replace(/\\\[(.*?)\\\]/gs, function (_, formula) {
115
+ try {
116
+ const trimmedFormula = formula.trim()
117
+ return renderToString(trimmedFormula, { displayMode: true });
118
+ } catch (error) {
119
+ console.error('Error rendering block formula:', error);
120
+ return _;
121
+ }
122
+ })
123
+ // $...$ 行内公式
124
+ .replace(/\$(.+?)\$/gs, function (_, formula) {
125
+ try {
126
+ const trimmedFormula = formula.trim()
127
+ return renderToString(trimmedFormula, { displayMode: false });
128
+ } catch (error) {
129
+ console.error('Error rendering inline formula with $...$:', error);
130
+ return _;
131
+ }
132
+ });
133
+ },
128
134
  },
129
135
  }
130
136
  </script>