扫一扫分享
markdown-it 是一个辅助解析 markdown 的库,可以完成从 # test 到 <h1>test</h1> 的转换。 它同时支持浏览器环境和 Node 环境,本质上和 babel 类似,不同之处在于,babel 解析的是 JavaScript。
安装
npm install markdown-it --save
bower install markdown-it --save
例子
// node.js, "classic" way:
var MarkdownIt = require('markdown-it'),
md = new MarkdownIt();
var result = md.render('# markdown-it rulezz!');
// node.js, the same, but with sugar:
var md = require('markdown-it')();
var result = md.render('# markdown-it rulezz!');
// browser without AMD, added to "window" on script load
// Note, there is no dash in "markdownit".
var md = window.markdownit();
var result = md.render('# markdown-it rulezz!');
单行渲染,无段落换行:
var md = require('markdown-it')();
var result = md.renderInline('__markdown-it__ rulezz!');
手机预览