forked from marijnh/Eloquent-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpre_epub.js
More file actions
30 lines (26 loc) · 822 Bytes
/
pre_epub.js
File metadata and controls
30 lines (26 loc) · 822 Bytes
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
// Script to pre-process the asciidoc sources for generating EPUB.
var fs = require("fs"), child = require("child_process");
var infile = process.argv[2];
var instream;
if (infile == "-") {
instream = process.stdin;
instream.resume();
} else {
instream = fs.createReadStream(infile);
}
var input = "";
instream.on("data", function(chunk) {
input += chunk;
});
instream.on("end", function() {
if (infile != "-")
input = ":docid: " + infile.match(/^\d{2}_(.*?)\.txt/)[1] + "\n" + input;
process.stdout.write(input.replace(/\blink:([^\.]+)\.html#(.*?)\[|!!(hint)!![^]+?!!hint!!(?:\n|$)/g,
function(match, linkFile, linkID, hint) {
if (linkFile) {
return "link:" + linkFile + ".xhtml#" + linkID + "[";
} else if (hint) {
return "";
}
}));
});