ai-error-assistant-pro 0.0.28 → 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 公式
@@ -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: {
@@ -200,8 +201,14 @@ export default {
200
201
  console.log(e);
201
202
  }
202
203
  },
203
- renderFormulas(text) {
204
+ renderFormulas(text) {
204
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, "'");
205
212
  // 如果整个文本包含 LaTeX 命令且没有定界符,整体包裹
206
213
  const hasDelimiter = /\$|\\\(|\\\[/.test(text);
207
214
  if (!hasDelimiter) {
@@ -212,44 +219,44 @@ export default {
212
219
  }
213
220
  const { renderToString } = katex;
214
221
  return text
215
- // 块级公式 $$...$$
216
- .replace(/\$\$(.*?)\$\$/gs, (match, p1) => {
222
+ // $$ ... $$ 块级公式
223
+ .replace(/\$\$([\s\S]*?)\$\$/gs, function (_, formula) {
217
224
  try {
218
- return renderToString(p1, { displayMode: true, throwOnError:
219
- false });
220
- } catch (e) {
221
- console.error('Block formula error:', e);
222
- return match;
225
+ const trimmedFormula = formula.trim()
226
+ return renderToString(trimmedFormula, { displayMode: true });
227
+ } catch (error) {
228
+ console.error('Error rendering block formula:', error);
229
+ return _;
223
230
  }
224
231
  })
225
- // 行内公式 $...$
226
- .replace(/\$(.*?)\$/g, (match, p1) => {
232
+ // \(...\) 行内公式
233
+ .replace(/\\\((.*?)\\\)/gs, function (_, formula) {
227
234
  try {
228
- return renderToString(p1, { displayMode: false, throwOnError:
229
- false });
230
- } catch (e) {
231
- console.error('Inline formula error:', e);
232
- return match;
235
+ const trimmedFormula = formula.trim()
236
+ return renderToString(trimmedFormula, { displayMode: false });
237
+ } catch (error) {
238
+ console.error('Error rendering inline formula:', error);
239
+ return _;
233
240
  }
234
241
  })
235
- // 行内公式 \( ... \)
236
- .replace(/\\\((.*?)\\\)/g, (match, p1) => {
242
+ // \[...\] 块级公式
243
+ .replace(/\\\[(.*?)\\\]/gs, function (_, formula) {
237
244
  try {
238
- return renderToString(p1, { displayMode: false, throwOnError:
239
- false });
240
- } catch (e) {
241
- console.error('Inline formula error:', e);
242
- return match;
245
+ const trimmedFormula = formula.trim()
246
+ return renderToString(trimmedFormula, { displayMode: true });
247
+ } catch (error) {
248
+ console.error('Error rendering block formula:', error);
249
+ return _;
243
250
  }
244
251
  })
245
- // 块级公式 \[ ... \]
246
- .replace(/\\\[(.*?)\\\]/gs, (match, p1) => {
252
+ // $...$ 行内公式
253
+ .replace(/\$(.+?)\$/gs, function (_, formula) {
247
254
  try {
248
- return renderToString(p1, { displayMode: true, throwOnError:
249
- false });
250
- } catch (e) {
251
- console.error('Block formula error:', e);
252
- return match;
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 _;
253
260
  }
254
261
  });
255
262
  },