feat: validate html elements in markdown, refactor cursor type, disable markdown input rendering

This commit is contained in:
kangfenmao 2024-11-19 11:45:00 +08:00
parent db779446f0
commit 223496192d
3 changed files with 7 additions and 4 deletions

View File

@ -18,6 +18,9 @@ import CodeBlock from './CodeBlock'
import ImagePreview from './ImagePreview' import ImagePreview from './ImagePreview'
import Link from './Link' import Link from './Link'
const ALLOWED_ELEMENTS =
/<(style|p|div|span|b|i|strong|em|ul|ol|li|table|tr|td|th|thead|tbody|h[1-6]|blockquote|pre|code|br|hr)/i
interface Props { interface Props {
message: Message message: Message
} }
@ -36,8 +39,8 @@ const Markdown: FC<Props> = ({ message }) => {
}, [message.content, message.status, t]) }, [message.content, message.status, t])
const rehypePlugins = useMemo(() => { const rehypePlugins = useMemo(() => {
const hasUnsafeElements = /<(input|textarea|select|menuitem)/i.test(messageContent) const hasElements = ALLOWED_ELEMENTS.test(messageContent)
return hasUnsafeElements ? [rehypeMath] : [rehypeRaw, rehypeMath] return hasElements ? [rehypeRaw, rehypeMath] : [rehypeMath]
}, [messageContent, rehypeMath]) }, [messageContent, rehypeMath])
if (message.role === 'user' && !renderInputMessageAsMarkdown) { if (message.role === 'user' && !renderInputMessageAsMarkdown) {

View File

@ -181,7 +181,7 @@ const ProviderListItem = styled.div`
align-items: center; align-items: center;
padding: 5px 8px; padding: 5px 8px;
width: 100%; width: 100%;
cursor: pointer; cursor: grab;
border-radius: 5px; border-radius: 5px;
font-size: 14px; font-size: 14px;
transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out;

View File

@ -56,7 +56,7 @@ const initialState: SettingsState = {
pasteLongTextAsFile: false, pasteLongTextAsFile: false,
clickAssistantToShowTopic: false, clickAssistantToShowTopic: false,
manualUpdateCheck: false, manualUpdateCheck: false,
renderInputMessageAsMarkdown: true, renderInputMessageAsMarkdown: false,
codeShowLineNumbers: false, codeShowLineNumbers: false,
codeCollapsible: false, codeCollapsible: false,
mathEngine: 'MathJax', mathEngine: 'MathJax',