-
Notifications
You must be signed in to change notification settings - Fork 8
/
findSections.groovy
61 lines (56 loc) · 1.71 KB
/
findSections.groovy
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
57
58
59
60
61
// Copyright (c) 2019-2022 Egon Willighagen <[email protected]>
//
// GPL v3
// find all topics and makes a data file to be converted into an Index
//
// it takes one optional argument, which is appended to the output
import groovy.xml.XmlSlurper
chapterCounters = new HashMap<String,String>();
chapterCounter = 0
appendixCounter = 0
def chapterLines = new File("order.txt").readLines()
chapterLines.each { String line ->
if (line.startsWith("app")) {
appendixCounter++
chapterCounters.put(line, (char)(64+appendixCounter))
} else {
chapterCounter++
chapterCounters.put(line, "" + chapterCounter)
}
}
figureCounter = 0;
chapters = "order.txt"
new File(chapters).eachLine { chapter ->
chapterCounter++
currentChapterCounter = chapterCounters.get(chapter)
file = "src/${chapter}.md"
sectionCounter = 0
subsectionCounter = 0
lines = new File(file).readLines()
figureInstructionText = ""
inFigure = false
lines.each { String line ->
if (line.startsWith("## ") && !line.contains("References")) {
subsectionCounter = 0
sectionCounter++
} else if (line.startsWith("### ")) {
subsectionCounter++
} else if (line.startsWith("<section")) {
def instruction = new XmlSlurper().parseText(line)
if (instruction.@level == "##") {
subsectionCounter = 0
sectionCounter++
} else if (instruction.@level == "###") {
subsectionCounter++
}
secNumber = "${currentChapterCounter}"
if (sectionCounter > 0) {
secNumber += ".${sectionCounter}"
if (subsectionCounter > 0) {
secNumber += ".${subsectionCounter}"
}
}
println "${instruction.@label}\t${chapter}\t${secNumber}"
}
}
}