forked from 1000ch/node-github-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfm.js
56 lines (49 loc) · 1.12 KB
/
gfm.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var fs = require('fs');
var path = require('path');
var _ = require('underscore');
var jade = require('jade');
var marked = require('marked');
var hljs = require('highlight.js');
var util = require('./lib/util');
marked.setOptions({
gfm: true,
tables: true,
breaks: true,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false,
highlight: function (code) {
return hljs.highlightAuto(code).value;
}
});
function GFM(file) {
// markdown files
if (util.isFile(file) && path.extname(file) === '.md') {
this.file = file;
} else {
throw new Error(file + ' is not a markdown file.');
}
}
GFM.prototype.render = function (callback) {
var name = path.basename(this.file);
var buffer = fs.readFileSync(this.file, {
encoding: 'utf8'
});
marked(buffer, function (error, content) {
if (error) {
throw error;
}
jade.renderFile(__dirname + '/assets/template.jade', {
pretty: true,
title: name,
content: content
}, function (error, html) {
if (error) {
throw error;
}
callback(html);
});
});
};
module.exports = GFM;