static-cms/src/components/Widgets/MarkdownPreview.js

21 lines
554 B
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
2016-05-30 16:55:32 -07:00
import CommonMark from 'commonmark';
2016-05-30 17:08:30 -07:00
import ReactRenderer from 'commonmark-react-renderer';
2016-05-30 16:55:32 -07:00
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,
};