-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcodescreenshot.js
More file actions
42 lines (34 loc) · 1.11 KB
/
codescreenshot.js
File metadata and controls
42 lines (34 loc) · 1.11 KB
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
var system = require('system'),
fs = require('fs'),
page = require('webpage').create();
var inputFile = system.args[1],
outputFile = inputFile.split('.'),
fileExtension = outputFile.pop(),
currentMode,
mimeType = system.args[2];
outputFile.push('png');
outputFile = outputFile.join('.');
page.open('codescreenshot/index.html', function() {
page.clipRect = {
top: 0,
left: 0,
width: 600,
height: 315
};
page.viewportSize = {
width: 600,
height: 315
};
page.onConsoleMessage = console.log.bind(console);
currentMode = page.evaluate(function(fileExtension) {
return window.CodeMirror.findModeByExtension(fileExtension);
}, fileExtension);
page.includeJs('https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.23.0/mode/' + currentMode.mode + '/' + currentMode.mode + '.min.js', function() {
page.evaluate(function(code, mimeType) {
window.CodeMirror.runMode(code, mimeType, document.querySelector('#snippet'));
}, fs.read(inputFile), mimeType || currentMode.mime);
page.render(outputFile);
console.log(outputFile);
phantom.exit();
});
});