fix: 移除 input 等输入标签的渲染
This commit is contained in:
parent
5b357f14e5
commit
969cf8ea21
@ -55,6 +55,8 @@
|
|||||||
|
|
||||||
p {
|
p {
|
||||||
margin: 1em 0;
|
margin: 1em 0;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
|
||||||
&:last-child {
|
&:last-child {
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,15 +21,6 @@ interface Props {
|
|||||||
message: Message
|
message: Message
|
||||||
}
|
}
|
||||||
|
|
||||||
const rehypePlugins = [rehypeRaw, rehypeMathjax]
|
|
||||||
const remarkPlugins = [remarkMath, remarkGfm]
|
|
||||||
|
|
||||||
const components = {
|
|
||||||
code: CodeBlock,
|
|
||||||
a: Link,
|
|
||||||
img: ImagePreview
|
|
||||||
}
|
|
||||||
|
|
||||||
const Markdown: FC<Props> = ({ message }) => {
|
const Markdown: FC<Props> = ({ message }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { renderInputMessageAsMarkdown } = useSettings()
|
const { renderInputMessageAsMarkdown } = useSettings()
|
||||||
@ -41,6 +32,11 @@ const Markdown: FC<Props> = ({ message }) => {
|
|||||||
return escapeBrackets(content)
|
return escapeBrackets(content)
|
||||||
}, [message.content, message.status, t])
|
}, [message.content, message.status, t])
|
||||||
|
|
||||||
|
const rehypePlugins = useMemo(() => {
|
||||||
|
const hasUnsafeElements = /<(input|textarea|select)/i.test(messageContent)
|
||||||
|
return hasUnsafeElements ? [rehypeMathjax] : [rehypeRaw, rehypeMathjax]
|
||||||
|
}, [messageContent])
|
||||||
|
|
||||||
if (message.role === 'user' && !renderInputMessageAsMarkdown) {
|
if (message.role === 'user' && !renderInputMessageAsMarkdown) {
|
||||||
return <p style={{ marginBottom: 5, whiteSpace: 'pre-wrap' }}>{messageContent}</p>
|
return <p style={{ marginBottom: 5, whiteSpace: 'pre-wrap' }}>{messageContent}</p>
|
||||||
}
|
}
|
||||||
@ -49,8 +45,14 @@ const Markdown: FC<Props> = ({ message }) => {
|
|||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
className="markdown"
|
className="markdown"
|
||||||
rehypePlugins={rehypePlugins}
|
rehypePlugins={rehypePlugins}
|
||||||
remarkPlugins={remarkPlugins}
|
remarkPlugins={[remarkMath, remarkGfm]}
|
||||||
components={components as Partial<Components>}
|
components={
|
||||||
|
{
|
||||||
|
a: Link,
|
||||||
|
code: CodeBlock,
|
||||||
|
img: ImagePreview
|
||||||
|
} as Partial<Components>
|
||||||
|
}
|
||||||
remarkRehypeOptions={{
|
remarkRehypeOptions={{
|
||||||
footnoteLabel: t('common.footnotes'),
|
footnoteLabel: t('common.footnotes'),
|
||||||
footnoteLabelTagName: 'h4',
|
footnoteLabelTagName: 'h4',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user