fix(Markdown): Conditionally apply MarkdownShadowDOMRenderer for style components based on message content

This commit is contained in:
kangfenmao 2025-04-06 09:11:23 +08:00
parent 7284679907
commit e02c967f5b

View File

@ -67,8 +67,7 @@ const Markdown: FC<Props> = ({ message, citationsData }) => {
}, },
code: CodeBlock, code: CodeBlock,
img: ImagePreview, img: ImagePreview,
pre: (props: any) => <pre style={{ overflow: 'visible' }} {...props} />, pre: (props: any) => <pre style={{ overflow: 'visible' }} {...props} />
style: MarkdownShadowDOMRenderer as any
} as Partial<Components> } as Partial<Components>
return baseComponents return baseComponents
}, [citationsData]) }, [citationsData])
@ -77,6 +76,10 @@ const Markdown: FC<Props> = ({ message, citationsData }) => {
return <p style={{ marginBottom: 5, whiteSpace: 'pre-wrap' }}>{messageContent}</p> return <p style={{ marginBottom: 5, whiteSpace: 'pre-wrap' }}>{messageContent}</p>
} }
if (messageContent.includes('<style>')) {
components.style = MarkdownShadowDOMRenderer as any
}
return ( return (
<ReactMarkdown <ReactMarkdown
rehypePlugins={rehypePlugins} rehypePlugins={rehypePlugins}