dev_forum
hjm 5 years ago
parent 73f23e9eaa
commit 4db7e1e058

@ -10,7 +10,8 @@ export function markdownToHTML(oldContent, selector) {
window.$(selector).html(oldContent)
} else {
try {
var markdwonParser = window.editormd.markdownToHTML("md_div", {
// selector ||
var markdwonParser = window.editormd.markdownToHTML(selector || "md_div", {
markdown: oldContent, // .replace(/▁/g,"▁▁▁"),
emoji: true,
htmlDecode: "style,script,iframe", // you can filter tags decode
@ -23,6 +24,10 @@ export function markdownToHTML(oldContent, selector) {
} catch(e) {
console.error(e)
}
// selector = '.' + selector
if (selector) {
return;
}
const content = window.$('#md_div').html()
if (selector) {

@ -0,0 +1,6 @@
.markdownToHtml.editormd-html-preview, .markdownToHtml.editormd-preview-container {
overflow: hidden;
}
.markdownToHtml.editormd-html-preview p.editormd-tex, .markdownToHtml.editormd-preview-container p.editormd-tex {
text-align: left;
}

@ -1,5 +1,6 @@
import React,{ Component } from "react";
import { markdownToHTML } from 'educoder'
import './MarkdownToHtml.css'
/**
selector 需要传入唯一的selector作为id不然会引起冲突
delay 如果有公式需要传入delay={true}
@ -14,9 +15,9 @@ class MarkdownToHtml extends Component{
if (this.props.delay == true) {
(function(content, selector) {
// console.log('selector: ', selector)
setTimeout(() => {
// setTimeout(() => {
markdownToHTML(content, selector)
}, 600)
// }, 600)
})(content, selector)
} else {
markdownToHTML(content, selector)
@ -25,18 +26,20 @@ class MarkdownToHtml extends Component{
componentDidUpdate = (prevProps) => {
if (this.props.content) {
if ( prevProps.content != this.props.content ) {
this._markdownToHTML(this.props.content, `.markdown_to_html_${this.props.selector || ''}`)
this._markdownToHTML(this.props.content, `markdown_to_html_${this.props.selector || ''}`)
}
}
}
componentDidMount () {
this.props.content && this._markdownToHTML(this.props.content, `.markdown_to_html_${this.props.selector || ''}`)
this.props.content && this._markdownToHTML(this.props.content, `markdown_to_html_${this.props.selector || ''}`)
}
render(){
const { style, className } = this.props
let _selector = `markdown_to_html_${this.props.selector || ''}`
return(
<div id="memo_content_editorMd" className={`new_li markdown-body ${className} markdown_to_html_${this.props.selector || ''}`}
<div id={_selector } className={`markdownToHtml new_li markdown-body ${className} ${_selector}`}
// dangerouslySetInnerHTML={{__html: markdownToHTML(this.props.content)}}
style={style}
>

Loading…
Cancel
Save