Files
talk/client/coral-framework/components/Markdown.js
T
2018-01-11 20:00:34 -07:00

26 lines
661 B
JavaScript

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import marked from 'marked';
const renderer = new marked.Renderer();
// Set link target to `_parent` to work properly in an embed.
renderer.link = (href, title, text) =>
`<a target="_parent" href="${href}" ${
title ? `title="${title}"` : ''
}>${text}</a>`;
marked.setOptions({ renderer });
export default class Markdown extends PureComponent {
render() {
const { content, ...rest } = this.props;
const __html = marked(content);
return <div {...rest} dangerouslySetInnerHTML={{ __html }} />;
}
}
Markdown.propTypes = {
content: PropTypes.string,
};