File tree Expand file tree Collapse file tree 3 files changed +50
-6
lines changed Expand file tree Collapse file tree 3 files changed +50
-6
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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)
You can’t perform that action at this time.
0 commit comments