fix: xml not render correctly (#3743)

This commit is contained in:
Faisal Amir 2024-09-30 15:30:02 +07:00 committed by GitHub
parent 7c63914e64
commit 87a8bc7359
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -53,6 +53,15 @@ const SimpleTextMessage: React.FC<ThreadMessage> = (props) => {
const clipboard = useClipboard({ timeout: 1000 }) const clipboard = useClipboard({ timeout: 1000 })
function escapeHtml(html: string): string {
return html
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
}
const marked: Marked = new Marked( const marked: Marked = new Marked(
markedHighlight({ markedHighlight({
langPrefix: 'hljs', langPrefix: 'hljs',
@ -69,6 +78,9 @@ const SimpleTextMessage: React.FC<ThreadMessage> = (props) => {
}), }),
{ {
renderer: { renderer: {
html: (html: string) => {
return escapeHtml(html) // Escape any HTML
},
link: (href, title, text) => { link: (href, title, text) => {
return Renderer.prototype.link return Renderer.prototype.link
?.apply(this, [href, title, text]) ?.apply(this, [href, title, text])