-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
39 lines (35 loc) · 1.06 KB
/
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
var path = require('path');
var phantom = require('phantom');
var Q = require('q');
module.exports = {
blocks: {
flowchart: {
process: function(blk) {
var deferred = Q.defer();
var code = blk.body;
var options = this.book.options.pluginsConfig['flowchart'];
var width = blk.kwargs['width'];
phantom.create().then(function(ph) {
ph.createPage().then(function(page) {
var pagePath = path.join(__dirname, 'renderer.html');
page.open(pagePath).then(function(status) {
var result = page.evaluate(function(code, options, width) {
return render(code, options, width);
}, code, options, width);
ph.exit();
deferred.resolve(result);
});
});
});
return deferred.promise;
}
}
},
hooks: {
"init": function() {
if (typeof this.options.pluginsConfig['flowchart'] === 'undefined') {
this.options.pluginsConfig['flowchart'] = {};
}
}
}
};