static-cms/src/components/Widgets/MarkdownPreview.js
2016-06-30 17:28:47 -03:00

21 lines
554 B
JavaScript

import React, { PropTypes } from 'react';
import CommonMark from 'commonmark';
import ReactRenderer from 'commonmark-react-renderer';
const parser = new CommonMark.Parser();
const renderer = new ReactRenderer();
export default class MarkdownPreview extends React.Component {
render() {
const { value } = this.props;
if (value == null) { return null; }
const ast = parser.parse(value);
return React.createElement.apply(React, ['div', {}].concat(renderer.render(ast)));
}
}
MarkdownPreview.propTypes = {
value: PropTypes.node,
};