Skip to content

Commit

Permalink
safe markdown renderer (#609, #403)
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Jan 26, 2024
1 parent faf5e87 commit 35cb508
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 1 deletion.
64 changes: 63 additions & 1 deletion src/components/MarkdownRender/markdown-without-katex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,73 @@ import remarkGfm from 'remark-gfm'
import remarkBreaks from 'remark-breaks'
import { Pre } from './Pre'
import { Hyperlink } from './Hyperlink'
import { memo } from 'react'

export function MarkdownRender(props) {
return (
<div dir="auto">
<ReactMarkdown
allowedElements={[
'div',
'p',
'span',

'video',
'img',

'abbr',
'acronym',
'b',
'blockquote',
'code',
'em',
'i',
'li',
'ol',
'ul',
'strong',
'table',
'tr',
'td',
'th',

'details',
'summary',
'kbd',
'samp',
'sub',
'sup',
'ins',
'del',
'var',
'q',
'dl',
'dt',
'dd',
'ruby',
'rt',
'rp',

'br',
'hr',

'h1',
'h2',
'h3',
'h4',
'h5',
'h6',

'thead',
'tbody',
'tfoot',
'u',
's',
'a',
'pre',
'cite',
]}
unwrapDisallowed={true}
remarkPlugins={[remarkGfm, remarkBreaks]}
rehypePlugins={[
rehypeRaw,
Expand Down Expand Up @@ -37,4 +99,4 @@ MarkdownRender.propTypes = {
...ReactMarkdown.propTypes,
}

export default MarkdownRender
export default memo(MarkdownRender)
61 changes: 61 additions & 0 deletions src/components/MarkdownRender/markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,67 @@ export function MarkdownRender(props) {
return (
<div dir="auto">
<ReactMarkdown
allowedElements={[
'div',
'p',
'span',

'video',
'img',

'abbr',
'acronym',
'b',
'blockquote',
'code',
'em',
'i',
'li',
'ol',
'ul',
'strong',
'table',
'tr',
'td',
'th',

'details',
'summary',
'kbd',
'samp',
'sub',
'sup',
'ins',
'del',
'var',
'q',
'dl',
'dt',
'dd',
'ruby',
'rt',
'rp',

'br',
'hr',

'h1',
'h2',
'h3',
'h4',
'h5',
'h6',

'thead',
'tbody',
'tfoot',
'u',
's',
'a',
'pre',
'cite',
]}
unwrapDisallowed={true}
remarkPlugins={[remarkMath, remarkGfm, remarkBreaks]}
rehypePlugins={[
rehypeKatex,
Expand Down

0 comments on commit 35cb508

Please sign in to comment.