contentful api markdown conversion to HTML

后端 未结 5 1960
滥情空心
滥情空心 2021-02-19 05:37

Is there any simple way to convert markdown text from contentful api to render into html code to be display on html page. I have tried using pagedown and some similar techniques

5条回答
  •  情书的邮戳
    2021-02-19 05:41

    I have used ReactMarkdown module: in case you also have a react app: https://github.com/rexxars/react-markdown

    Example: npm install --save react-markdown

    const React = require('react')
    const ReactDOM = require('react-dom')
    const ReactMarkdown = require('react-markdown')
    
    const input = '# This is a header\n\nAnd this is a paragraph'
    
    ReactDOM.render(
      ,
      document.getElementById('container')
    )
    

    I am passing markdown through props and using this module inside of my child component.

提交回复
热议问题