forked from Experience-Monks/devtool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown.js
42 lines (34 loc) · 1.05 KB
/
markdown.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
/*
This demo renders markdown documents to an image.
- Reads markdown from stdin
- Renders it to the document.body with GFM
- Shows the browser window and captures the screen
- Writes PNG to process.stdout
npm run example:markdown
*/
var marked = require('marked');
var remote = require('electron').remote;
var css = require.resolve('github-markdown-css/github-markdown.css');
var cssFile = require('fs').readFileSync(css, 'utf8');
require('insert-css')(cssFile);
require('get-stdin')()
.then(function (src) {
capture(src.toString());
}, function (err) {
console.error(err);
process.exit(1);
});
function capture (md) {
document.body.className = 'markdown-body';
document.body.innerHTML = marked(md);
var browserWindow = remote.getCurrentWindow();
browserWindow.show();
browserWindow.setContentSize(720, 640);
setTimeout(function () { // wait for images to render
browserWindow.capturePage(function (data) {
process.stdout.write(data.toPng(), function () {
window.close();
});
});
}, 500);
}