forgeplus-react/src/components/render-html.jsx

21 lines
670 B
React
Raw Normal View History

2020-04-28 17:23:34 +08:00
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
2020-04-29 15:27:55 +08:00
console.log(html, '----========')
html = html.replace(/▁/g, "▁▁▁")
2020-04-28 17:23:34 +08:00
const el = useRef()
useEffect(() => {
if (el.current && html) {
2020-04-29 15:27:55 +08:00
if (html.match(preRegex)) {
2020-04-28 17:23:34 +08:00
window.PR.prettyPrint()
}
}
}, [html, el.current])
return (<div ref={el} style={style} className={`${className} markdown-body`} dangerouslySetInnerHTML={{ __html: html }}></div>)
}