有没有集成了hexo风格的markdown转html的nodejs库啊,我找了半天没找到,然后自己研究了半天hexo中使用的hexo-renderer-marked库,也是没有解决!
想问下有没有大神有没有什么好的转换库?
补充:markdowm库和marked库我都试过了,只是原生的转换,我想要的库是像hexo转换那样,添加了一些类,比如代码高亮,行号显示等。
markdownJS
var fs = require('fs'),
markdown = require("./markdown"),
fileContent;
// 读入 Markdown 源文件
fileContent = fs.readFileSync('test.md', 'utf8');
// 使用 MarkdownJS 模块把源文件转换为 HTML 源代码
fileContent = markdown.toHTML(fileContent);
// 保存
fs.writeFileSync('test.html', fileContent);
http://www.cnblogs.com/sanshi/archive/2011/03/16/1986468.html
我用过一个库,不知道能帮你吗
https://github.com/chjj/marked
我用这个库做了简单markdown阅读器,可以自己下下来玩玩
https://github.com/hjzheng/markdown-reader
语法和代码高亮建议结合 https://github.com/google/code-prettify 一块使用
这个我没试过,但是 marked 将
例如下面的代码
用 ' 代替 ` 显示
'''css
.class {
background: url(data:image/gif;base64,R0lGODl ... ) no-repeat left center;
}
'''
转成了
<pre>
<code class="lang-css"> .class {
background: url(data:image/gif;base64,R0lGODl ... ) no-repeat left center;
}
</code>
</pre>
结合 code-prettify ,你只需要在 pre 元素上加上 class=“prettyprint”, 你可以在node中添加,也可以在html用js动态添加
Hexo 中使用的是 marked。