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
24 lines (20 loc) · 825 Bytes
/
extract_hints.js
File metadata and controls
24 lines (20 loc) · 825 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
const {readdirSync, readFileSync} = require("fs")
process.stdout.write("# 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");
for (let name of readdirSync(".")) {
if (!/^\d\d.*\.md$/.test(name)) continue
let file = readFileSync(name, "utf8")
let title = file.match(/(?:\n|^)# (.*?)\n/)[1], titleWritten = false
let curSubsection
let re = /\n### (.*?)\n|\{\{hint\n([^]+?)\nhint\}\}/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].trim()}\n\n`)
}
}
}