页面右侧聊天助手的ai输出结果加上md文档格式显示
This commit is contained in:
@@ -74,12 +74,22 @@
|
||||
import { ref, computed, watch, nextTick, onMounted } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useStore } from 'vuex'
|
||||
import markdownit from 'markdown-it'
|
||||
import MemberDialog from '@/components/MemberDialog.vue'
|
||||
import AiThinkingIndicator from '@/components/tools/AiThinkingIndicator.vue'
|
||||
import { sendNovaChat } from '@/utils/aiRequest'
|
||||
import type { NovaChatHistoryItem } from '@/utils/aiRequest'
|
||||
import { fetchResumeList } from '@/api/resume'
|
||||
|
||||
// ==================== Markdown 渲染实例 ====================
|
||||
|
||||
/** markdown-it 实例,用于将 AI 回复的 Markdown 文本渲染为 HTML */
|
||||
const md = markdownit({
|
||||
html: false, // 禁止原始 HTML(防 XSS)
|
||||
breaks: true, // 将换行符转为 <br>
|
||||
linkify: true, // 自动识别链接
|
||||
})
|
||||
|
||||
// ==================== Props ====================
|
||||
|
||||
/** 组件属性 */
|
||||
@@ -180,9 +190,9 @@ const userQuestions = computed(() => quickQuestions.value)
|
||||
|
||||
// ==================== 内容格式化 ====================
|
||||
|
||||
/** 将消息中的换行符转为 HTML 换行标签 */
|
||||
/** 将消息内容通过 markdown-it 渲染为 HTML */
|
||||
function formatContent(content: string): string {
|
||||
return content.replace(/\n/g, '<br>')
|
||||
return md.render(content)
|
||||
}
|
||||
|
||||
// ==================== 滚动控制 ====================
|
||||
|
||||
Reference in New Issue
Block a user