node.js - Markdown转HTML库
伊谢尔伦
伊谢尔伦 2017-04-17 14:25:49
[Node.js讨论组]
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(3)
高洛峰

我用过一个库,不知道能帮你吗
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动态添加

PHP中文网

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

高洛峰

Hexo 中使用的是 marked。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号