File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
src/sphinx_substitution_extensions Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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"
You can’t perform that action at this time.
0 commit comments