Skip to content

Commit 30b1ba3

Browse files
Merge #493
493: Do not lowercase paragraph ids for link anchors r=pietroalbini a=Veykril Co-authored-by: Lukas Wirth <[email protected]>
2 parents 2f68cc3 + 4336c11 commit 30b1ba3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

exts/ferrocene_spec/definitions/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class DefIdNode(nodes.Element):
2222
def __init__(self, kind, text):
2323
text, id = parse_target_from_text(text)
24-
super().__init__(def_kind=kind, def_text=text, def_id=id_from_text(id))
24+
super().__init__(def_kind=kind, def_text=text, def_id=id_from_text(kind, id))
2525

2626
def astext(self):
2727
return self["def_text"]
@@ -35,7 +35,7 @@ def __init__(self, kind, source_doc, text):
3535
ref_kind=kind,
3636
ref_source_doc=source_doc,
3737
ref_text=text,
38-
ref_target=id_from_text(target),
38+
ref_target=id_from_text(kind, target),
3939
)
4040

4141
def astext(self):
@@ -211,8 +211,17 @@ def get_object_types():
211211
return result
212212

213213

214-
def id_from_text(text):
215-
return "".join(c if c.isalnum() else "_" for c in text.lower())
214+
def id_from_text(kind, text):
215+
# We lowercase the text so that capitalization does not matter for
216+
# references and definitions, which is sometimes the case for when they are
217+
# used as the start of a sentence.
218+
# Notably though, this breaks for paragraph ids which are unique randomized
219+
# strings where capitalization matters for hyperlinking, so we don't do so
220+
# for those
221+
return "".join(
222+
c if c.isalnum() else "_"
223+
for c in (text if kind == "paragraph" else text.lower())
224+
)
216225

217226

218227
def setup(app):

exts/ferrocene_spec/paragraph_ids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def build_finished(app, exception):
6767
if exception is not None:
6868
return
6969

70-
with sphinx.util.progress_message("dumping paragraph ids"):
70+
with sphinx.util.display.progress_message("dumping paragraph ids"):
7171
write_paragraph_ids(app)
7272

7373

0 commit comments

Comments
 (0)