contentful api markdown conversion to HTML

后端 未结 5 2234
滥情空心
滥情空心 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 06:01

    Here's how I did it with React:

    class NewsDetail extends React.Component {
        render() {
            const body = marked(this.props.body || "");
            return (
                    

    {this.props.title}

    ); } }

    The markdown content is stored in the body attribute of the NewsDetail tag (via a short function that maps contentful data structure to my app structure).

    The HTML page has this script tag to pull in the marked function:

    
    

提交回复
热议问题