-
Notifications
You must be signed in to change notification settings - Fork 11
/
findFigures.groovy
47 lines (43 loc) · 1.45 KB
/
findFigures.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
// Copyright (c) 2018-2022 Egon Willighagen <[email protected]>
//
// GPL v3
import groovy.xml.XmlSlurper
chapterCounters = new HashMap<String,String>();
chapterCounter = 0
def chapterLines = new File("order.txt").readLines()
chapterLines.each { String line ->
chapterCounter++
chapterCounters.put(line, "" + chapterCounter)
}
figureCounter = 0;
chapters = "order.txt"
new File(chapters).eachLine { chapter ->
chapterCounter++
currentChapterCounter = chapterCounters.get(chapter)
file = "${chapter}.i.md"
figureCounter = 0
lines = new File(file).readLines()
figureInstructionText = ""
inFigure = false
lines.each { String line ->
if (inFigure && !line.contains("</figure>")) {
figureInstructionText += line
return
} else if (line.contains("</figure>")) {
figureEnd = line.indexOf("</figure>")
figureInstructionText += line.substring(0, figureEnd+9)
// now process the XML
def figuresInstruction = new XmlSlurper().parseText(figureInstructionText)
figNumber = "${currentChapterCounter}.${figureCounter}"
if (figuresInstruction.@label != null && !([email protected]())) {
println "${figuresInstruction.@label}\t${chapter}\t${figNumber}"
}
inFigure = false
} else if (line.startsWith("<figure")) {
inFigure = true
figureCounter++
figureStart = line.indexOf("<figure")
figureInstructionText = line.substring(figureStart)
}
}
}