Skip to content

Commit 87d9b57

Browse files
committed
Fix more p’s with xml:ids
1 parent ba64072 commit 87d9b57

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

pretext/Recursion/ConvertinganIntegertoaStringinAnyBase.ptx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
we have just performed is illustrated in <xref ref="recursion_fig-tostr"/>. Notice that
5353
the numbers we want to remember are in the remainder boxes along the
5454
right side of the diagram.</p>
55-
<p xml:id="recursion_fig-tostr" names="fig_tostr"><term>Figure 4.3:</term> Converting an Integer to a String in Base 10</p>
56-
<figure align="center">
55+
<figure xml:id="recursion_fig-tostr" align="center">
5756
<image source="Recursion/Figures/toStr.png" width="50%" alt="image"/>
5857
</figure>
5958
<p><xref ref="lst-rectostr"/> shows the Python code that implements the algorithm

pretext/Recursion/VisualizingRecursion.ptx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,11 @@ main()
143143
going as far out to the left as possible. Rather, once again the entire
144144
right side of the left tree is drawn until we finally make our way out
145145
to the smallest twig on the left.</p>
146-
<p xml:id="recursion_fig-tree1" names="fig_tree1"><term>Figure 4.7:</term> The Beginning of a Fractal Tree</p>
147-
<figure align="center">
146+
<figure xml:id="recursion_fig-tree1" align="center">
148147
<image source="Recursion/Figures/tree1.png" width="50%"/>
149148
</figure>
150-
<p xml:id="recursion_fig-tree2" names="fig_tree2"><term>Figure 8:</term> The First Half of the Tree</p>
151-
<figure align="center">
149+
150+
<figure xml:id="recursion_fig-tree2" align="center">
152151
<image source="Recursion/Figures/tree2.png" width="50%"/>
153152
</figure>
154153
<p>This simple tree program is just a starting point for you, and you will

pretext/fix_xrefs.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# fix_xrefs
2+
import re
3+
import os
4+
import pdb
5+
6+
xref_dict = {}
7+
8+
for root, dirs, files in os.walk("pretext"):
9+
for file in files:
10+
if "toctree" in file:
11+
continue
12+
if ".ptx" in file:
13+
with open(os.path.join(root, file)) as f:
14+
text = f.read()
15+
16+
all_xrefs = re.findall(r'<xref ref="((lst-|fig-).*?)".*?>', text)
17+
for ref in all_xrefs:
18+
if target := re.search(
19+
r'xml:id="((.*?_.*?)+' + ref[0] + ')"', text
20+
):
21+
print(target.groups(1))
22+
# pdb.set_trace()
23+
xref_dict[ref[0]] = target.groups(1)[0]
24+
25+
26+
for root, dirs, files in os.walk("pretext"):
27+
for file in files:
28+
if "toctree" in file:
29+
continue
30+
if ".ptx" in file:
31+
with open(os.path.join(root, file)) as f:
32+
text = f.read()
33+
34+
all_xrefs = re.findall(r'<xref ref="((lst-|fig-).*?)".*?>', text)
35+
for ref in all_xrefs:
36+
target = ref[0]
37+
# pdb.set_trace()
38+
if target in xref_dict:
39+
text = text.replace(
40+
f'<xref ref="{target}"', f'<xref ref="{xref_dict[target]}"'
41+
)
42+
43+
with open(os.path.join(root, file), "w") as f:
44+
f.write(text)
45+
46+
# print(xref_dict)

0 commit comments

Comments
 (0)