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

17 lines
480 B
JavaScript
Raw Normal View History

2016-05-30 16:55:32 -07:00
import React from 'react';
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)));
}
}