Utilisez le markdown-to-jsx
paquet npm. aquí est l'exemple des modèles de l'interface utilisateur du matériel.
Il faut essentiellement créer un objet de configuration que ReactMarkdown apprécie et qui est spécifique à l'interface matérielle.
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} />;
}
Je l'ai appris directement de leur exemple.