diff --git a/public/react/src/common/TextUtil.js b/public/react/src/common/TextUtil.js index 82a848cac..8aef0adbd 100644 --- a/public/react/src/common/TextUtil.js +++ b/public/react/src/common/TextUtil.js @@ -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) { diff --git a/public/react/src/common/components/markdown/MarkdownToHtml.css b/public/react/src/common/components/markdown/MarkdownToHtml.css new file mode 100644 index 000000000..affba12cd --- /dev/null +++ b/public/react/src/common/components/markdown/MarkdownToHtml.css @@ -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; +} \ No newline at end of file diff --git a/public/react/src/common/components/markdown/MarkdownToHtml.js b/public/react/src/common/components/markdown/MarkdownToHtml.js index 0780fc789..c7d15cf64 100644 --- a/public/react/src/common/components/markdown/MarkdownToHtml.js +++ b/public/react/src/common/components/markdown/MarkdownToHtml.js @@ -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( -