【发布时间】:2016-10-18 16:44:10
【问题描述】:
目前我知道如何使用 gulp 将 json 数据注入到 jam 中,但是我的 json 数据中的 markdown 格式不正确。我听说过marked,但不确定如何在我的 gulp 文件或jade 文件中使用它。
我直接使用管道数据
.pipe(data(JSON.parse(fs.readFileSync(file)))
.pipe(pug())
.pipe(gulp.dest(destdir))
我试过了
.pipe(data(marked(JSON.parse(fs.readFileSync(file)))))
和
.pipe(marked(data(JSON.parse(fs.readFileSync(file)))))
都说 TypeError: src.replace is not a function
我不确定如何将marked 嵌入此处或我的玉代码中。有什么建议吗?
已编辑
因此,我对从JSON.parse 获得的 json 对象进行了一些预处理。在注入我的玉数据之前,我首先为每个 json 对象中的字符串 marked 编写了一个函数。比如:
var marked = require("marked")
function preprocess(){
var data = JSON.parse(fs.readFileSync(file));
iterate through data and do marked(string)
return data
}
现在我可以将渲染的字符串转换成jade,但是jade无法理解markdown符号,例如<p> </p>在我的网页中按字面意思显示为<p> </p>。有什么解决方法吗?
【问题讨论】: