-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcore.js
56 lines (45 loc) · 1012 Bytes
/
core.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
#!/usr/bin/env javascript
var marked = require("marked")
function transpile(input) {
return marked.lexer(input).
filter(function(block) {
return block.type === "code"
}).map(function(block) {
return block.text
}).join("\n\n")
}
function compile(input, output) {
var source = "";
input.on("data", function onChunck(chunck) {
source = source.concat(chunck)
});
input.once("end", function onRead() {
try {
output.write(transpile(source))
} catch (error) {
exit(error)
}
})
input.on("error", exit)
output.on("error", exit)
}
function exit(error) {
if (error) {
console.error(error)
process.exit(1)
} else {
process.exit(0)
}
}
function main() {
if (process.argv.length < 3) {
process.stdin.resume()
process.stdin.setEncoding("utf8")
compile(process.stdin, process.stdout)
} else {
Module._load(path.resolve(process.argv[2]), null, true);
}
}
if (require.main === module)
main()
module.exports = main