Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not lowercase paragraph ids for link anchors #493

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 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,17 @@ 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
Loading