I am using Contentful's Rich-Text Field type to build pages, one of the Embedded_Blocks I have is for a Markdown field type which I am using to build a table:
Markdown Field Type:
| Title | Title |
| ---------- | ---------- |
| Cell | Cell |
I can retrieve the Rich-Text data and build out my Embedded_Blocks like this:
[BLOCKS.EMBEDDED_ENTRY]: (node) => {
const fields = node.data.target.fields;
switch (node.data.target.sys.contentType.sys.id) {
case 'video':
const url = (fields.url['en-US']);
return <Video url={url}/>
// This is how I'm currently trying to convert Markdown to HTML
///////////////////////////////////////////////////////////////
case 'markdown':
const markdown = (fields.markdown['en-US']);
console.log('markdown', markdown);
return <div dangerouslySetInnerHTML={{ __html: markdown }} />
default:
return <div>Fallback</div>
}
},
The problem I have with this is that it just returns a string, I'm assuming because I have not converted markdown
to HTML before passing it to dangerouslySetInnerHTML={{ __html: markdown }}
.
How can I convent the Markdown to HTML so that I can render it using dangerouslySetInnerHTML={{ __html: markdown }}
?