Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80551 views
1
import React from 'react';
2
import Remarkable from 'remarkable';
3
4
const md = new Remarkable({
5
html: true,
6
linkify: true,
7
typographer: true,
8
highlight: (str, lang) => {
9
if (typeof Prism === 'undefined') return;
10
11
if (lang === 'js') lang = 'javascript';
12
13
if (!lang || !Prism.languages[lang]) return;
14
15
return Prism.highlight(str, Prism.languages[lang]);
16
}
17
});
18
19
class Markdown extends React.Component {
20
21
render() {
22
const { src, ...props } = this.props;
23
const html = md.render(src);
24
25
return (
26
<div
27
{...props}
28
dangerouslySetInnerHTML={{ __html: html }}
29
/>
30
);
31
}
32
}
33
34
Markdown.defaultProps = {
35
src: '',
36
};
37
38
export default Markdown;
39
40