Make your website support markdown

Get showdown.js, this is the js needed to change the style

This is their github, https://github.com/showdownjs/showdown
but let's use the imported bootcdn showdown.min.js.
http://www.bootcdn.cn/showdown/

Make website settings

Introduced in html

<script src="https://cdn.bootcss.com/showdown/1.8.6/showdown.js"></script>

Our article is in a div with an id of postcont

<!--文章内容开始-->
    <div id="postcont" style="white-space: pre">文章内容</div>
    <script>
    var converter = new showdown.Converter();
    var post      = document.getElementById('postcont');
    var  text      = post.textContent||post.innerText;//获取文本内容, post.textContent是非ie所用,post.innerText是ie所用,
    var html      = converter.makeHtml(text);          //这里写成这样是为了兼容
    post.innerHTML=html;
    </script>
    <!--文章内容结束-->

Effect:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325124899&siteId=291194637