Use the markdown-to-jsx
npm package. here is the example from the material ui templates.
You basically have to create a config object that ReactMarkdown likes, that is specific for material ui
import React from 'react';
import ReactMarkdown from 'markdown-to-jsx';
import { withStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import Link from '@material-ui/core/Link';
const styles = (theme) => ({
listItem: {
marginTop: theme.spacing(1),
},
});
const options = {
overrides: {
h1: {
component: Typography,
props: {
gutterBottom: true,
variant: 'h5',
},
},
h2: { component: Typography, props: { gutterBottom: true, variant: 'h6' } },
h3: { component: Typography, props: { gutterBottom: true, variant: 'subtitle1' } },
h4: {
component: Typography,
props: { gutterBottom: true, variant: 'caption', paragraph: true },
},
p: { component: Typography, props: { paragraph: true } },
a: { component: Link },
li: {
component: withStyles(styles)(({ classes, ...props }) => (
<li className={classes.listItem}>
<Typography component="span" {...props} />
</li>
)),
},
},
};
export default function Markdown(props) {
return <ReactMarkdown options={options} {...props} />;
}
I got that straight from their example.
marked
over a react specific library that has easier support for this? – Rotz