forked from marijnh/Eloquent-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_hints.js
More file actions
25 lines (21 loc) · 861 Bytes
/
extract_hints.js
File metadata and controls
25 lines (21 loc) · 861 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
var fs = require("fs");
process.stdout.write(":docid: hints\n\n= Exercise Hints =\n\nThe hints below might help when you are stuck with one of the exercises in this book. They don't give away the entire solution, but rather try to help you find it yourself.\n\n");
fs.readdirSync(".").forEach(function(name) {
var m = /^(\d\d.*)\.txt$/.exec(name);
if (!m) return;
var file = fs.readFileSync(name, "utf8");
var title = file.match(/\n= (.*?) =\n/)[1], titleWritten = false;
var curSubsection;
var re = /\n=== (.*?) ===|!!hint!!([^]+?)!!hint!!/g;
while (m = re.exec(file)) {
if (m[1]) {
curSubsection = m[1];
} else {
if (!titleWritten) {
process.stdout.write("== " + title + " ==\n\n");
titleWritten = true;
}
process.stdout.write("=== " + curSubsection + " ===\n\n" + m[2] + "\n");
}
}
});