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.
- package/components/demo/src/chat.vue +58 -41
- package/components/demo/src/error-chat.vue +61 -43
- package/dist/ai-error-assistant-pro.common.js +2971 -63
- package/dist/ai-error-assistant-pro.common.js.map +1 -1
- package/dist/ai-error-assistant-pro.css +1 -1
- package/dist/ai-error-assistant-pro.umd.js +2971 -63
- package/dist/ai-error-assistant-pro.umd.js.map +1 -1
- package/dist/ai-error-assistant-pro.umd.min.js +4 -4
- package/dist/ai-error-assistant-pro.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
})
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
416
|
+
if (!text) return '';
|
|
417
|
+
text = text.replace(/>/g, '>')
|
|
418
|
+
.replace(/</g, '<')
|
|
419
|
+
.replace(/&/g, '&')
|
|
420
|
+
.replace(/"/g, '"')
|
|
421
|
+
.replace(/'/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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
205
|
+
if (!text) return '';
|
|
206
|
+
|
|
207
|
+
text = text.replace(/>/g, '>')
|
|
208
|
+
.replace(/</g, '<')
|
|
209
|
+
.replace(/&/g, '&')
|
|
210
|
+
.replace(/"/g, '"')
|
|
211
|
+
.replace(/'/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>
|