MarkDown支持html语法
marked.js
marked是一个markdown 解析、编译器
以下代码是如何将md文件转为html
import marked from 'marked'
let renderMD = new marked.Renderer();
let index = 0;
renderMD.heading = function (text, level) {
return `<h${level} class="my-blog-head" id="my-blog-head${index++}">${text}</h${level}>`
}
marked.setOptions({
renderer: renderMD,
gfm: true,
pedantic: false,
sanitize: false,
tables: true,
breaks: true,
smartLists: true,
smartypants: true
});
export default function markdown (str) {
return marked(str);
}
marked的具体使用方法请参见这篇文章