-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 979 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var gutil = require('gulp-util');
var through = require('through2');
var concat = require('concat-stream');
var hammerdown = require('hammerdown');
module.exports = function gulpHammerdown(options){
'use strict';
return through.obj(function (file, enc, cb) {
var self = this;
if (file.isNull()) {
this.push(file);
return cb();
}
var hammerDownStream = hammerdown(options);
hammerDownStream.on('error',function(error){
self.emit('error', new gutil.PluginError('gulp-hammerdown', error));
});
if (file.isStream()) {
file.contents = file.contents.pipe(hammerDownStream);
return onComplete(self,file,cb);
}
if(file.isBuffer()){
hammerDownStream.parse(file.contents).pipe(concat(function(data){
file.contents = new Buffer(data.toString());
return onComplete(self,file,cb);
}));
}
});
};
var onComplete = function(stream,file,done){
file.path = gutil.replaceExtension(file.path,'.md');
stream.push(file);
return done();
};