From 048dcadaacd2294c37ff1d9bd195376ab2a4be46 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 2 May 2024 13:30:11 +0200 Subject: [PATCH] Do not lowercase paragraph ids for link anchors --- exts/ferrocene_spec/definitions/__init__.py | 14 ++++++++++---- exts/ferrocene_spec/paragraph_ids.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/exts/ferrocene_spec/definitions/__init__.py b/exts/ferrocene_spec/definitions/__init__.py index 3d7d47c8..c4011e21 100644 --- a/exts/ferrocene_spec/definitions/__init__.py +++ b/exts/ferrocene_spec/definitions/__init__.py @@ -21,7 +21,7 @@ class DefIdNode(nodes.Element): def __init__(self, kind, text): text, id = parse_target_from_text(text) - super().__init__(def_kind=kind, def_text=text, def_id=id_from_text(id)) + super().__init__(def_kind=kind, def_text=text, def_id=id_from_text(kind, id)) def astext(self): return self["def_text"] @@ -35,7 +35,7 @@ def __init__(self, kind, source_doc, text): ref_kind=kind, ref_source_doc=source_doc, ref_text=text, - ref_target=id_from_text(target), + ref_target=id_from_text(kind, target), ) def astext(self): @@ -211,8 +211,14 @@ def get_object_types(): return result -def id_from_text(text): - return "".join(c if c.isalnum() else "_" for c in text.lower()) +def id_from_text(kind, text): + # We lowercase the text so that capitalization does not matter for + # references and definitions, which is sometimes the case for when they are + # used as the start of a sentence. + # Notably though, this breaks for paragraph ids which are unique randomized + # strings where capitalization matters for hyperlinking, so we don't do so + # for those + return "".join(c if c.isalnum() else "_" for c in (text if kind == "paragraph" else text.lower())) def setup(app): diff --git a/exts/ferrocene_spec/paragraph_ids.py b/exts/ferrocene_spec/paragraph_ids.py index 48551dd0..8440406f 100644 --- a/exts/ferrocene_spec/paragraph_ids.py +++ b/exts/ferrocene_spec/paragraph_ids.py @@ -67,7 +67,7 @@ def build_finished(app, exception): if exception is not None: return - with sphinx.util.progress_message("dumping paragraph ids"): + with sphinx.util.display.progress_message("dumping paragraph ids"): write_paragraph_ids(app)