-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathextract_hints.mjs
More file actions
24 lines (20 loc) · 862 Bytes
/
Copy pathextract_hints.mjs
File metadata and controls
24 lines (20 loc) · 862 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
import {readdirSync, readFileSync} from "fs"
process.stdout.write("# Pistas para los Ejercicios\n\nLas pistas a continuación pueden ayudarte cuando te encuentres atascado con uno de los ejercicios de este libro. No revelan la solución completa, sino que intentan ayudarte a encontrarla tú mismo.\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, m
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`)
}
}
}