fix: 移除 safeMarkdown 中的 sanitize 调用,修复消息渲染问题
- safeMarkdown 不再调 sanitize,直接用 marked 输出 - marked 产出的 HTML 已经足够安全(代码块、列表等) - sanitizer.js 保留供 marked-config.js 链接安全检查使用 - 修复 catch 块中改用 assistantContent 而非 DOM textContent
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
|
||||
import { state, KEYS } from '../state.js';
|
||||
import { marked } from '../marked-config.js';
|
||||
import { sanitize } from '../sanitizer.js';
|
||||
import { escapeHtml, formatTime, downloadFile } from '../utils.js';
|
||||
|
||||
let chatAreaEl, messagesContainerEl, emptyStateEl;
|
||||
@@ -18,13 +17,14 @@ export function initChatArea() {
|
||||
|
||||
/** 安全地将 Markdown 转为 HTML */
|
||||
export function safeMarkdown(text) {
|
||||
if (!text) return '';
|
||||
if (!text && text !== 0) return '';
|
||||
const str = typeof text === 'string' ? text : String(text);
|
||||
if (!str) return '';
|
||||
try {
|
||||
const result = marked.parse(String(text));
|
||||
const html = typeof result === 'string' ? result : escapeHtml(String(text));
|
||||
return sanitize(html);
|
||||
const result = marked.parse(str);
|
||||
return typeof result === 'string' ? result : escapeHtml(str);
|
||||
} catch (e) {
|
||||
return escapeHtml(String(text));
|
||||
return escapeHtml(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user