2022-03-09 17:57:44 -05:00
|
|
|
import { memo, useEffect, useState } from "react"
|
2022-03-08 19:39:24 -05:00
|
|
|
import ReactMarkdownPreview from "./react-markdown-preview"
|
2022-03-06 19:46:59 -05:00
|
|
|
|
2022-03-09 17:57:44 -05:00
|
|
|
type Props = {
|
|
|
|
content?: string
|
|
|
|
height?: number | string
|
|
|
|
// file extensions we can highlight
|
|
|
|
type?: string
|
|
|
|
}
|
|
|
|
|
|
|
|
const MarkdownPreview = ({ content = '', height = 500, type = 'markdown' }: Props) => {
|
|
|
|
const [contentToRender, setContent] = useState(content)
|
|
|
|
useEffect(() => {
|
|
|
|
// 'm' so it doesn't flash code when you change the type to md
|
|
|
|
const renderAsMarkdown = ['m', 'markdown', 'md', 'mdown', 'mkdn', 'mkd', 'mdwn', 'mdtxt', 'mdtext', 'text', '']
|
|
|
|
if (!renderAsMarkdown.includes(type)) {
|
|
|
|
setContent(`~~~${type}
|
|
|
|
${content}
|
|
|
|
~~~
|
|
|
|
`)
|
|
|
|
} else {
|
|
|
|
setContent(content)
|
|
|
|
}
|
|
|
|
}, [type, content])
|
|
|
|
return (<ReactMarkdownPreview height={height} content={contentToRender} />)
|
2022-03-06 19:46:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(MarkdownPreview)
|