Skip to content

Commit

Permalink
sphinx.ext.extlinks: Add extlink-{name} CSS class to links (#12319)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed May 15, 2024
1 parent 9467bf7 commit c06f246
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
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

0 comments on commit c06f246

Please sign in to comment.