@@ -14,15 +14,35 @@ class FerroceneSortIds(SphinxTransform):
14
14
# Run this step after sphinx sorted.
15
15
default_priority = SortIds .default_priority + 1
16
16
17
- def apply (self , ** kwargs ):
17
+ def apply (self ):
18
18
for node in self .document .findall (nodes .section ):
19
19
for n , id in enumerate (node ["ids" ]):
20
- if id .startswith ("fls-" ):
21
- node ["ids" ][n ] = id [:3 ] + "_" + id [4 :]
20
+ node ["ids" ][n ] = normalize_fls_id (id )
22
21
# sort the fls id to the back
23
22
if len (node ["ids" ]) > 1 and node ["ids" ][0 ].startswith ("fls_" ):
24
23
node ["ids" ] = node ["ids" ][1 :] + [node ["ids" ][0 ]]
25
24
26
25
26
+ class NormalizeFlsReferences (SphinxTransform ):
27
+ default_priority = 500
28
+
29
+ def apply (self ):
30
+ for reference in self .document .findall (nodes .reference ):
31
+ if "internal" not in reference or not reference ["internal" ]:
32
+ continue
33
+ if "refuri" not in reference or "#" not in reference ["refuri" ]:
34
+ continue
35
+ path , hash = reference ["refuri" ].rsplit ("#" , 1 )
36
+ reference ["refuri" ] = f"{ path } #{ normalize_fls_id (hash )} "
37
+
38
+
39
+ def normalize_fls_id (id ):
40
+ if id .startswith ("fls-" ):
41
+ return id .replace ("fls-" , "fls_" , 1 )
42
+ else :
43
+ return id
44
+
45
+
27
46
def setup (app ):
28
47
app .add_transform (FerroceneSortIds )
48
+ app .add_post_transform (NormalizeFlsReferences )
0 commit comments