Skip to content

Commit 3981bdd

Browse files
Merge pull request #1060 from adamtheturtle/download-class
Require and give substitution-download the same classes as `download`
2 parents 5679535 + aee0dcd commit 3981bdd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/sphinx_substitution_extensions/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ class SubstitutionXRefRole(XRefRole):
133133
Custom role for XRefs.
134134
"""
135135

136+
def create_xref_node(self) -> tuple[list[Node], list[system_message]]:
137+
"""Override parent method to set classes.
138+
139+
This is a bit of a hack because it assumes that the role name
140+
will be `substitution-<class_name>` and that we want to remove
141+
the `substitution-`.
142+
"""
143+
for index, class_name in enumerate(iterable=self.classes):
144+
self.classes[index] = class_name.replace("substitution-", "")
145+
146+
return super().create_xref_node()
147+
136148
def process_link(
137149
self,
138150
env: BuildEnvironment,
@@ -175,7 +187,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
175187
)
176188
app.add_role(name="substitution-code", role=SubstitutionCodeRole())
177189
substitution_download_role = SubstitutionXRefRole(
178-
nodeclass=addnodes.download_reference
190+
nodeclass=addnodes.download_reference,
179191
)
180192
app.add_role(name="substitution-download", role=substitution_download_role)
181193
return {"parallel_read_safe": True}

tests/test_substitution_extensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def test_substitution_download(
227227
'<a class="reference download internal" download="" '
228228
'href="_downloads/.*/tgt_pre-example_substitution-tgt_post%20.py">'
229229
"<code "
230-
'class="xref substitution-download docutils literal notranslate"'
230+
'class="xref download docutils literal notranslate"'
231231
">"
232232
'<span class="pre">'
233233
"txt_pre-example_substitution-txt_post"

0 commit comments

Comments
 (0)