2017-03-10 83 views
0

我想使用「gulp-markdown-to-json」將自述文件轉換爲json。當我從命令行運行gulp我得到'TypeError:md2json.parse不是一個函數'。使用gulp json降價

這裏是我的依賴

"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

嘗試[降價到JSON(HTTPS://pypi.python .org/pypi/markdown-to-json/1.0.0)Python包,如果你確定使用其他語言, –

回答

0

我覺得你在這裏混合兩種東西:

據一口,降價到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()

有幾個markdown解析器可用,但您必須嘗試使用​​它們來查看哪一個(使用正確的配置)最適合您的需求。

從文檔的輸出指示在bodymarked所述解析器輸出的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" 
}