ai-error-assistant-pro 0.0.27 → 0.0.29

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.
@@ -93,6 +93,7 @@ import { chartClear, sendMessageEventSource, getAutoQuestioning, pdfUrl, pdfUrlB
93
93
  import katex from 'katex';
94
94
  import renderMathInElement from 'katex/contrib/auto-render/auto-render.js'
95
95
  import 'katex/dist/katex.min.css';
96
+ import 'katex/contrib/mhchem/mhchem.js';
96
97
  const controller = new AbortController();
97
98
  const signal = controller.signal;
98
99
 
@@ -412,47 +413,63 @@ export default {
412
413
  window.open(baseUrl, '_blank');
413
414
  },
414
415
  renderFormulas(text) {
415
- const {renderToString} = katex;
416
- return text
417
- .replace(/\$\$(.*?)\$\$/gs, (match) => {
418
- try {
419
- // 渲染块级公式
420
- return renderToString(match.slice(2, -2), {displayMode: false});
421
- } catch (error) {
422
- console.error('Error rendering block formula:', error);
423
- return match;
424
- }
425
- })
426
- .replace(/\$.*?\$/g, (match) => {
427
- match = match.replace(/<br>/g, '');
428
- try {
429
- // 渲染行内公式
430
- return renderToString(match.slice(1, -1), {displayMode: false});
431
- } catch (error) {
432
- console.error('Error rendering inline formula:', error);
433
- return match;
434
- }
435
- })
436
- .replace(/\\\(.*?\\\)/g, (match) => {
437
- try {
438
- // 渲染行内公式
439
- return renderToString(match.slice(2, -2), {displayMode: false});
440
- } catch (error) {
441
- console.error('Error rendering inline formula:', error);
442
- return match;
443
- }
444
- })
445
- .replace(/\\\[[\s\S]*?\\\]/g, (match) => {
446
- match = match.replace(/<br>/g, '');
447
- try {
448
- // 渲染块级公式
449
- return renderToString(match.slice(2, -2), {displayMode: false});
450
- } catch (error) {
451
- console.error('Error rendering block formula:', error);
452
- return match;
453
- }
454
- });
455
- },
416
+ if (!text) return '';
417
+ text = text.replace(/&gt;/g, '>')
418
+ .replace(/&lt;/g, '<')
419
+ .replace(/&amp;/g, '&')
420
+ .replace(/&quot;/g, '"')
421
+ .replace(/&#39;/g, "'");
422
+ // 如果整个文本包含 LaTeX 命令且没有定界符,整体包裹
423
+ const hasDelimiter = /\$|\\\(|\\\[/.test(text);
424
+ if (!hasDelimiter) {
425
+ text = text.replace(
426
+ /(\\(?: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,
427
+ (match) => `\\(${match}\\)`
428
+ );
429
+ }
430
+ const { renderToString } = katex;
431
+ return text
432
+ // $$ ... $$ 块级公式
433
+ .replace(/\$\$([\s\S]*?)\$\$/gs, function (_, formula) {
434
+ try {
435
+ const trimmedFormula = formula.trim()
436
+ return renderToString(trimmedFormula, { displayMode: true });
437
+ } catch (error) {
438
+ console.error('Error rendering block formula:', error);
439
+ return _;
440
+ }
441
+ })
442
+ // \(...\) 行内公式
443
+ .replace(/\\\((.*?)\\\)/gs, function (_, formula) {
444
+ try {
445
+ const trimmedFormula = formula.trim()
446
+ return renderToString(trimmedFormula, { displayMode: false });
447
+ } catch (error) {
448
+ console.error('Error rendering inline formula:', error);
449
+ return _;
450
+ }
451
+ })
452
+ // \[...\] 块级公式
453
+ .replace(/\\\[(.*?)\\\]/gs, function (_, formula) {
454
+ try {
455
+ const trimmedFormula = formula.trim()
456
+ return renderToString(trimmedFormula, { displayMode: true });
457
+ } catch (error) {
458
+ console.error('Error rendering block formula:', error);
459
+ return _;
460
+ }
461
+ })
462
+ // $...$ 行内公式
463
+ .replace(/\$(.+?)\$/gs, function (_, formula) {
464
+ try {
465
+ const trimmedFormula = formula.trim()
466
+ return renderToString(trimmedFormula, { displayMode: false });
467
+ } catch (error) {
468
+ console.error('Error rendering inline formula with $...$:', error);
469
+ return _;
470
+ }
471
+ });
472
+ },
456
473
  renderKaTeX() {
457
474
  setTimeout(() => {
458
475
  // 自动渲染页面中的所有 KaTeX 公式
@@ -33,7 +33,7 @@
33
33
  style="padding-bottom: 24px"
34
34
  v-if="questionStem.type === 'shortanswer' || questionStem.type === 'gapfilling'">
35
35
  <span style="vertical-align: inherit; display: inline-block">正确答案:</span>
36
- <span style="margin-left: 8px; display: inline-block; width: calc(100% - 82px); vertical-align: top;" v-html="questionStem.answer.join(',')"></span>
36
+ <span style="margin-left: 8px; display: inline-block; width: calc(100% - 82px); vertical-align: top;" v-html="renderFormulas(questionStem.answer.join(','))"></span>
37
37
  </div>
38
38
  <div class="student-answer-part">
39
39
  <div class="check-content" style="width: 24px; margin-right: 16px">
@@ -56,7 +56,7 @@
56
56
  <!-- {{ item }}<span v-if="index !== questionStem.studentAnswer.length - 1">,</span>-->
57
57
  <!-- </span>-->
58
58
  <div v-if="questionStem.type === 'shortanswer' || questionStem.type === 'gapfilling'">
59
- <span style="margin-left: 8px" v-html="questionStem.studentAnswer.join(',')"></span>
59
+ <span style="margin-left: 8px" v-html="renderFormulas(questionStem.studentAnswer.join(','))"></span>
60
60
  </div>
61
61
  </div>
62
62
  </div>
@@ -91,6 +91,7 @@ import ChatTools from './chat-tools.vue';
91
91
  import {erranalysis, pdfUrlBase, retryAnalysis} from '../api/index'
92
92
  import katex from 'katex';
93
93
  import 'katex/dist/katex.min.css';
94
+ import 'katex/contrib/mhchem/mhchem.js';
94
95
  export default {
95
96
  name: 'ErrorChart',
96
97
  components: {
@@ -201,47 +202,64 @@ export default {
201
202
  }
202
203
  },
203
204
  renderFormulas(text) {
204
- const {renderToString} = katex;
205
- return text
206
- .replace(/\$\$(.*?)\$\$/gs, (match) => {
207
- try {
208
- // 渲染块级公式
209
- return renderToString(match.slice(2, -2), {displayMode: false});
210
- } catch (error) {
211
- console.error('Error rendering block formula:', error);
212
- return match;
213
- }
214
- })
215
- .replace(/\$.*?\$/g, (match) => {
216
- match = match.replace(/<br>/g, '');
217
- try {
218
- // 渲染行内公式
219
- return renderToString(match.slice(1, -1), {displayMode: false});
220
- } catch (error) {
221
- console.error('Error rendering inline formula:', error);
222
- return match;
223
- }
224
- })
225
- .replace(/\\\(.*?\\\)/g, (match) => {
226
- try {
227
- // 渲染行内公式
228
- return renderToString(match.slice(2, -2), {displayMode: false});
229
- } catch (error) {
230
- console.error('Error rendering inline formula:', error);
231
- return match;
232
- }
233
- })
234
- .replace(/\\\[[\s\S]*?\\\]/g, (match) => {
235
- match = match.replace(/<br>/g, '');
236
- try {
237
- // 渲染块级公式
238
- return renderToString(match.slice(2, -2), {displayMode: false});
239
- } catch (error) {
240
- console.error('Error rendering block formula:', error);
241
- return match;
242
- }
243
- });
244
- },
205
+ if (!text) return '';
206
+
207
+ text = text.replace(/&gt;/g, '>')
208
+ .replace(/&lt;/g, '<')
209
+ .replace(/&amp;/g, '&')
210
+ .replace(/&quot;/g, '"')
211
+ .replace(/&#39;/g, "'");
212
+ // 如果整个文本包含 LaTeX 命令且没有定界符,整体包裹
213
+ const hasDelimiter = /\$|\\\(|\\\[/.test(text);
214
+ if (!hasDelimiter) {
215
+ text = text.replace(
216
+ /(\\(?: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,
217
+ (match) => `\\(${match}\\)`
218
+ );
219
+ }
220
+ const { renderToString } = katex;
221
+ return text
222
+ // $$ ... $$ 块级公式
223
+ .replace(/\$\$([\s\S]*?)\$\$/gs, function (_, formula) {
224
+ try {
225
+ const trimmedFormula = formula.trim()
226
+ return renderToString(trimmedFormula, { displayMode: true });
227
+ } catch (error) {
228
+ console.error('Error rendering block formula:', error);
229
+ return _;
230
+ }
231
+ })
232
+ // \(...\) 行内公式
233
+ .replace(/\\\((.*?)\\\)/gs, function (_, formula) {
234
+ try {
235
+ const trimmedFormula = formula.trim()
236
+ return renderToString(trimmedFormula, { displayMode: false });
237
+ } catch (error) {
238
+ console.error('Error rendering inline formula:', error);
239
+ return _;
240
+ }
241
+ })
242
+ // \[...\] 块级公式
243
+ .replace(/\\\[(.*?)\\\]/gs, function (_, formula) {
244
+ try {
245
+ const trimmedFormula = formula.trim()
246
+ return renderToString(trimmedFormula, { displayMode: true });
247
+ } catch (error) {
248
+ console.error('Error rendering block formula:', error);
249
+ return _;
250
+ }
251
+ })
252
+ // $...$ 行内公式
253
+ .replace(/\$(.+?)\$/gs, function (_, formula) {
254
+ try {
255
+ const trimmedFormula = formula.trim()
256
+ return renderToString(trimmedFormula, { displayMode: false });
257
+ } catch (error) {
258
+ console.error('Error rendering inline formula with $...$:', error);
259
+ return _;
260
+ }
261
+ });
262
+ },
245
263
  }
246
264
  }
247
265
  </script>