对话消息体适配图片输出 wj

This commit is contained in:
CZH 2025-08-07 11:44:25 +08:00
parent db96d7fca2
commit f6c84eb2ee
1 changed files with 5 additions and 3 deletions

View File

@ -687,6 +687,8 @@ const parseECharts = (text: string): { processedText: string; echarts: EChartDat
//
const formatAnswer = async (text: string) => {
try {
// text += `\n\n![](http://192.168.1.211:12211/files/202508_.png)`
// ECharts
const { processedText, echarts } = parseECharts(text)
@ -715,16 +717,16 @@ const formatAnswer = async (text: string) => {
).replace(
/<td>/g,
'<td style="border: 1px solid #cbd5e1; padding: 12px;">'
)
).replace(/<img /g, '<img loading="lazy" style="max-width: 100%; display: block; margin: 1rem auto;" ')
const sanitizedHtml = DOMPurify.sanitize(wrappedHtml, {
ALLOWED_TAGS: [
'strong', 'em', 'code', 'pre', 'a', 'br', 'p',
'ul', 'ol', 'li', 'h1', 'h2', 'h3', 'span',
'blockquote', 'hr', 'table', 'thead', 'tbody',
'tr', 'th', 'td', 'div', 'details', 'summary'
'tr', 'th', 'td', 'div', 'details', 'summary', 'img'
],
ALLOWED_ATTR: ['href', 'target', 'class', 'style', 'data-chart-id', 'border', 'cellspacing', 'cellpadding', 'open']
ALLOWED_ATTR: ['href', 'target', 'class', 'style', 'data-chart-id', 'border', 'cellspacing', 'cellpadding', 'open','src', 'alt', 'loading', 'style']
}) as string
console.log('Markdown输入:', processedText)