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

sphinx.ext.extlinks: Add extlink-{name} CSS class to links #12319

Merged
merged 3 commits into from
May 15, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/internals/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Please follow these guidelines when writing code for Sphinx:

Style and type checks can be run as follows::

ruff .
ruff check .
mypy sphinx/

Unit tests
Expand Down
5 changes: 3 additions & 2 deletions sphinx/ext/extlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def check_uri(self, refnode: nodes.reference) -> None:

def make_link_role(name: str, base_url: str, caption: str) -> RoleFunction:
# Check whether we have base_url and caption strings have an '%s' for
# expansion. If not, fall back the the old behaviour and use the string as
# expansion. If not, fall back to the old behaviour and use the string as
# a prefix.
# Remark: It is an implementation detail that we use Pythons %-formatting.
# Remark: It is an implementation detail that we use Python's %-formatting.
# So far we only expose ``%s`` and require quoting of ``%`` using ``%%``.
def role(typ: str, rawtext: str, text: str, lineno: int,
inliner: Inliner, options: dict[str, Any] | None = None,
Expand All @@ -108,6 +108,7 @@ def role(typ: str, rawtext: str, text: str, lineno: int,
else:
title = caption % part
pnode = nodes.reference(title, title, internal=False, refuri=full_url)
pnode["classes"].append(f"extlink-{name}")
return [pnode], []
return role

Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_5_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ def checker(nodes):
('extensions.html', ".//a[@href='https://python.org/dev/']", "https://python.org/dev/"),
('extensions.html', ".//a[@href='https://bugs.python.org/issue1000']", "issue 1000"),
('extensions.html', ".//a[@href='https://bugs.python.org/issue1042']", "explicit caption"),
('extensions.html', ".//a[@class='extlink-pyurl reference external']", "https://python.org/dev/"),
('extensions.html', ".//a[@class='extlink-issue reference external']", "issue 1000"),

# index entries
('genindex.html', ".//a/strong", "Main"),
Expand Down