-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (31 loc) · 1002 Bytes
/
index.js
File metadata and controls
39 lines (31 loc) · 1002 Bytes
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
'use strict';
var fs = require('fs');
var path = require('path');
var gutil = require('gulp-util');
var through = require('through2');
var markdownIt = require('markdown-it');
var cheerio = require('cheerio');
var $ = cheerio.load(fs.readFileSync(path.resolve(__dirname, 'template.html')), 'utf-8');
module.exports = function (options) {
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-markdown-github-style', 'Streaming not supported'));
return;
}
var md = markdownIt(options);
var data = md.render(file.contents.toString());
$('article')
.empty()
.append(data)
.find('a[href*=".md"]').each(function () {
$(this).attr('href', $(this).attr('href').replace('.md', '.html'));
});
file.contents = new Buffer($.html());
file.path = gutil.replaceExtension(file.path, '.html');
cb(null, file);
});
};