import matter from 'gray-matter' ; import { parse as mdParse } from './parse' ; import { renderer } from './renderer' ; import { AnchorLinkProvider } from 'components/markdown/Heading' ; const toJSON = ( value ) => JSON . parse ( JSON . stringify ( value ) ) ; export const parseMatter = ( md ) => matter ( md , { excerpt_separator : '<!-- more -->' } ) ; export const parse = async ( markdown ) => { const md = parseMatter ( markdown ) ; const mdast = toJSON ( await mdParse ( md . content ) ) ; return { markdown , mdast , data : toJSON ( md . data ) } ; } ; export const renderToReact = ( mdast , { anchorLink = true } = { } ) => ( < AnchorLinkProvider value = { anchorLink } > { renderer ( mdast ) } < /AnchorLinkProvider>);