feat: enable more HTML restrictions in comments

This commit is contained in:
DIYgod 2023-04-24 12:59:06 +01:00
parent 3a8b501bbd
commit 347e10e215
No known key found for this signature in database
3 changed files with 7 additions and 3 deletions

View File

@ -95,6 +95,7 @@ export const CommentItem: React.FC<{
</div>
<PageContent
content={comment.metadata?.content?.content}
isComment={true}
></PageContent>
<div className="mt-1 flex items-center">
<Reactions

View File

@ -14,6 +14,7 @@ export const PageContent: React.FC<{
onScroll?: (scrollTop: number) => void
onMouseEnter?: () => void
parsedContent?: ReturnType<typeof renderPageContent>
isComment?: boolean
}> = ({
className,
content,
@ -22,6 +23,7 @@ export const PageContent: React.FC<{
onScroll,
onMouseEnter,
parsedContent,
isComment,
}) => {
useCodeCopy()
@ -29,12 +31,12 @@ export const PageContent: React.FC<{
if (parsedContent) {
return parsedContent
} else if (content) {
const result = renderPageContent(content)
const result = renderPageContent(content, false, isComment)
return result
} else {
return null
}
}, [content, parsedContent])
}, [content, isComment, parsedContent])
useEffect(() => {
const hashChangeHandler = () => {

View File

@ -75,6 +75,7 @@ const rehypePrism = rehypePrismGenerator(refractor)
export const renderPageContent = (
content: string,
html?: boolean,
simple?: boolean,
): Rendered => {
const env: MarkdownEnv = {
excerpt: "",
@ -162,7 +163,7 @@ export const renderPageContent = (
]
},
})
.use(rehypeSanitize, sanitizeScheme)
.use(rehypeSanitize, simple ? undefined : sanitizeScheme)
.use(rehypeTable)
.use(rehypeExternalLink)
.use(rehypeWrapCode)