mirror of
https://github.com/wassname/talk.git
synced 2026-06-30 05:10:08 +08:00
26 lines
661 B
JavaScript
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,
|
|
};
|