1.9.0前端

fix(AI):AI问答显示markdown内容解析问题修复
master^2
xs 2 days ago
parent ef9d89936f
commit 481a901ab9

@ -368,10 +368,7 @@
<script setup lang="ts">
import {ref, reactive, computed, nextTick, onMounted, onUnmounted} from 'vue'
import axios from 'axios'
import request from '@/utils/request';
import {getToken} from "@/utils/auth";
const {proxy} = getCurrentInstance() as ComponentInternalInstance;
import {ElMessage, ElMessageBox} from 'element-plus'
@ -1109,12 +1106,56 @@ function scrollToBottom() {
}
function formatMessage(content: string) {
// markdown
return content
// \\n \n
let formatted = content.replace(/\\n/g, '\n');
//
formatted = formatted.replace(/\n/g, '<br>');
// markdown
formatted = formatted
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\*(.*?)\*/g, '<em>$1</em>')
.replace(/`(.*?)`/g, '<code>$1</code>')
.replace(/\n/g, '<br>')
.replace(/`(.*?)`/g, '<code>$1</code>');
// ###/##/#
formatted = formatted
.replace(/### (.*?)<br>/g, '<h3>$1</h3><br>')
.replace(/## (.*?)<br>/g, '<h2>$1</h2><br>')
.replace(/# (.*?)<br>/g, '<h1>$1</h1><br>');
// -
formatted = formatted.replace(/ - (.*?)<br>/g, '<li>$1</li><br>');
// liul
formatted = formatted.replace(/(<li>.*?<\/li><br>)+/g, (match) => {
const cleanLi = match.replace(/<br>$/, '');
return `<ul style="padding-left: 20px;">${cleanLi}</ul><br>`;
});
// 线---
formatted = formatted.replace(/---<br>/g, '<hr><br>');
// MES
formatted = formatted.replace(/(\|.*?\|.*?<br>)+/g, (tableMatch) => {
const rows = tableMatch.split('<br>').filter(row => row.trim() !== '');
if (rows.length < 2) return tableMatch;
let tableHtml = '<table border="1" cellpadding="8" cellspacing="0" style="width: 100%; margin: 8px 0;"><tbody>';
rows.forEach((row, index) => {
const cells = row.split('|').filter(cell => cell.trim() !== '');
if (cells.length === 0) return;
const cellTag = index === 0 ? 'th' : 'td';
tableHtml += '<tr>';
cells.forEach(cell => {
tableHtml += `<${cellTag}>${cell.trim()}</${cellTag}>`;
});
tableHtml += '</tr>';
});
tableHtml += '</tbody></table><br>';
return tableHtml;
});
return formatted;
}
function formatTime(timestamp: number) {

Loading…
Cancel
Save