forked from Gitlink/forgeplus-react
20 lines
661 B
React
20 lines
661 B
React
|
|
import React, { useEffect, useRef } from 'react'
|
||
|
|
import 'katex/dist/katex.min.css';
|
||
|
|
import { exportMdtoHtml } from 'educoder'
|
||
|
|
|
||
|
|
let preRegex = /<pre[^>]*>/g
|
||
|
|
export default ({ value = '', is_md = true, className, style = {} }) => {
|
||
|
|
let html = is_md ? exportMdtoHtml(value) : value
|
||
|
|
html = html.replace(/▁/g, "▁▁▁").replace('<p>[TOC]</p>', '')
|
||
|
|
const el = useRef()
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
if (el.current && html) {
|
||
|
|
if (preRegex.test(html)) {
|
||
|
|
window.PR.prettyPrint()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}, [html, el.current])
|
||
|
|
|
||
|
|
return (<div ref={el} style={style} className={`${className} markdown-body`} dangerouslySetInnerHTML={{ __html: html }}></div>)
|
||
|
|
}
|