Integrated MarkitupReactRenderer with Preview pane

This commit is contained in:
Andrey Okonetchnikov 2016-09-22 21:53:57 +02:00
parent 04c9780ee1
commit 9392fdbe30

View File

@ -1,28 +1,23 @@
import React, { PropTypes } from 'react'; import React, { PropTypes } from 'react';
import MarkupIt from 'markup-it';
import { getSyntaxes } from './richText'; import { getSyntaxes } from './richText';
import MarkitupReactRenderer from './MarkitupReactRenderer';
export default class MarkdownPreview extends React.Component { const MarkdownPreview = ({ value }) => {
if (value == null) {
constructor(props) { return null;
super(props);
const { markdown, html } = getSyntaxes();
this.markdown = new MarkupIt(markdown);
this.html = new MarkupIt(html);
} }
render() {
const { value } = this.props;
if (value == null) { return null; }
const content = this.markdown.toContent(value);
const contentHtml = { __html: this.html.toText(content) };
const { markdown } = getSyntaxes();
return ( return (
<div dangerouslySetInnerHTML={contentHtml} /> <MarkitupReactRenderer
value={value}
syntax={markdown}
/>
); );
} };
}
MarkdownPreview.propTypes = { MarkdownPreview.propTypes = {
value: PropTypes.node, value: PropTypes.string,
}; };
export default MarkdownPreview;