Skip to content

Commit

Permalink
Do not lowercase paragraph ids for link anchors
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed May 2, 2024
1 parent 2082e80 commit 048dcad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions exts/ferrocene_spec/definitions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion exts/ferrocene_spec/paragraph_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 048dcad

Please sign in to comment.