|
@@ -120,7 +120,7 @@ import DOMPurify from 'dompurify'; // 用
|
|
|
import CodeBlock from './CodeBlock.vue';
|
|
|
|
|
|
import { h, render } from 'vue';
|
|
|
-
|
|
|
+let StartCode = false
|
|
|
export default {
|
|
|
name: 'AIChatBox',
|
|
|
components: {
|
|
@@ -511,7 +511,7 @@ export default {
|
|
|
let match;
|
|
|
// console.log(regex.exec(text))
|
|
|
while ((match = regex.exec(text)) !== null) {
|
|
|
- this.startCode = false
|
|
|
+ StartCode = false
|
|
|
// 添加代码块之前的文本
|
|
|
if (match.index > lastIndex) {
|
|
|
blocks.push({
|
|
@@ -537,13 +537,13 @@ export default {
|
|
|
let lastContent = text.slice(lastIndex)
|
|
|
let regex2 = /```(\w*)\n([\s\S]+)/g;
|
|
|
let lastResult
|
|
|
- let index = 0
|
|
|
+ let index1 = 0
|
|
|
while((lastResult = regex2.exec(lastContent)) !== null){
|
|
|
- this.startCode = true
|
|
|
- if(lastResult.index > index){
|
|
|
+ StartCode = true
|
|
|
+ if(lastResult.index > index1){
|
|
|
blocks.push({
|
|
|
type: 'text',
|
|
|
- content: lastContent.slice(index, lastResult.index),
|
|
|
+ content: lastContent.slice(index1, lastResult.index),
|
|
|
isComplete: false
|
|
|
});
|
|
|
}
|
|
@@ -553,12 +553,11 @@ export default {
|
|
|
content: lastResult[2].trim(),
|
|
|
isComplete: true // 代码块总是完整显示
|
|
|
});
|
|
|
-
|
|
|
- index = regex2.lastIndex;
|
|
|
+ index1 = regex2.lastIndex;
|
|
|
}
|
|
|
- lastIndex = lastIndex + index
|
|
|
+ lastIndex = lastIndex + index1
|
|
|
}
|
|
|
- if(lastIndex < text.length && !this.startCode){
|
|
|
+ if(lastIndex < text.length && !StartCode){
|
|
|
blocks.push({
|
|
|
type: 'text',
|
|
|
content: text.slice(lastIndex),
|