1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-10-16 15:07:27 +00:00
festa/components/generic/renderers/markdown.tsx

29 lines
916 B
TypeScript

import { memo } from "react"
import { default as ReactMarkdown } from "react-markdown"
type FestaMarkdownRendererProps = {
code: string,
}
/**
* Component rendering Markdown source with {@link ReactMarkdown}, using some custom settings to better handle user input.
*
* Currently, it converts `h1` and `h2` into `h3`, and disables the rendering of `img` elements.
*/
export const FestaMarkdownRenderer = memo(({ code }: FestaMarkdownRendererProps) => {
return (
<ReactMarkdown
components={{
h1: "h2", // h1 is reserved for the page name
h2: "h3",
h3: "h4",
h4: "h5",
h5: "h6",
img: undefined, // images reveal the IP of the user to third parties!
}}
>
{code}
</ReactMarkdown>
)
})
FestaMarkdownRenderer.displayName = "FestaMarkdownRenderer"