我想使用“gulp-markdown-to-json”将自述文件转换为json。当我从命令行运行gulp时,我得到'TypeError:md2json.parse不是函数'。
这是我的依赖
"devDependencies": {
"browserify": "^14.1.0",
"gulp-install": "^0.6.0",
"gulp-markdown-to-json": "^1.0.3",
"watchify": "^3.9.0"
},
"dependencies": {
"gulp": "^3.9.1",
"jquery": "^3.1.1",
"watchify": "^3.9.0"
}
gulp.js
var gulp = require('gulp');
var md2json = require('gulp-markdown-to-json');
gulp.task('default', function() {
return gulp.src('test.md')
.pipe(md2json.parse())
.pipe(gulp.dest('.'));
})
答案 0 :(得分:0)
我认为你在这里混合了两件事:
根据gulp-markdown-to-json的#usage:
const gulp = require('gulp');
const markdownToJSON = require('gulp-markdown-to-json');
const marked = require('marked');
marked.setOptions({
pedantic: true,
smartypants: true
});
gulp.task('markdown', () => {
gulp.src('./content/**/*.md')
.pipe(markdownToJSON(marked))
.pipe(gulp.dest('.'))
});
上例中没有md2json.parse()
。
有一些降价解析器可用,但您必须尝试使用它们来查看哪一个(具有适当的配置)最符合您的需求。
文档的输出表明marked
解析器在body
中输出html,这可能不是您想要的结果:
{
"slug": "bushwick-artisan",
"title": "Wes Anderson pop-up Bushwick artisan",
"layout": "centered",
"body": "<h2 id="yolo">YOLO</h2>\n<p>Chia quinoa meh, you probably haven't heard of them sartorial Holowaychuk pickled post-ironic. Plaid ugh vegan, Sixpoint 8-bit sartorial artisan semiotics put a bird on it Mission bicycle rights Club-Mate vinyl.</p>",
"updatedAt": "1970-01-01T00:00:00Z"
}