对话消息体适配图片输出 wj
This commit is contained in:
parent
db96d7fca2
commit
f6c84eb2ee
|
@ -687,6 +687,8 @@ const parseECharts = (text: string): { processedText: string; echarts: EChartDat
|
|||
// 格式化答案
|
||||
const formatAnswer = async (text: string) => {
|
||||
try {
|
||||
// text += `\n\n`
|
||||
|
||||
// 先解析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)
|
||||
|
|
Loading…
Reference in New Issue