Skip to content

Commit 71af280

Browse files
committed
fix references to fls sections being broken
1 parent 92f4ba7 commit 71af280

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

exts/ferrocene_spec/sphinx_fixes.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,35 @@ class FerroceneSortIds(SphinxTransform):
1414
# Run this step after sphinx sorted.
1515
default_priority = SortIds.default_priority + 1
1616

17-
def apply(self, **kwargs):
17+
def apply(self):
1818
for node in self.document.findall(nodes.section):
1919
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)
2221
# sort the fls id to the back
2322
if len(node["ids"]) > 1 and node["ids"][0].startswith("fls_"):
2423
node["ids"] = node["ids"][1:] + [node["ids"][0]]
2524

2625

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+
2746
def setup(app):
2847
app.add_transform(FerroceneSortIds)
48+
app.add_post_transform(NormalizeFlsReferences)

0 commit comments

Comments
 (0)