Skip to content

Commit cc737ee

Browse files
committed
Config to enable/disable using hoverxref over domains
1 parent 0b61189 commit cc737ee

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

hoverxref/extension.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,23 @@ def copy_asset_files(app, exception):
177177
)
178178

179179

180+
def setup_domains(app, config):
181+
# Add ``hoverxref`` role replicating the behavior of ``ref``
182+
app.add_role_to_domain(
183+
'std',
184+
'hoverxref',
185+
XRefRole(
186+
lowercase=True,
187+
innernodeclass=nodes.inline,
188+
warn_dangling=True,
189+
),
190+
)
191+
app.add_domain(HoverXRefStandardDomain, override=True)
192+
193+
if 'py' in config.hoverxref_domains:
194+
app.add_domain(HoverXRefPythonDomain, override=True)
195+
196+
180197
def setup(app):
181198
"""Setup ``hoverxref`` Sphinx extension."""
182199

@@ -190,6 +207,7 @@ def setup(app):
190207
app.add_config_value('hoverxref_auto_ref', False, 'env')
191208
app.add_config_value('hoverxref_mathjax', False, 'env')
192209
app.add_config_value('hoverxref_sphinxtabs', False, 'env')
210+
app.add_config_value('hoverxref_domains', [], 'env')
193211

194212
app.add_config_value('hoverxref_tooltip_api_host', 'https://readthedocs.org', 'env')
195213
app.add_config_value('hoverxref_tooltip_theme', ['tooltipster-shadow', 'tooltipster-shadow-custom'], 'env')
@@ -206,20 +224,7 @@ def setup(app):
206224
# replace this as well
207225
app.set_translator('readthedocs', HoverXRefHTMLTranslator, override=True)
208226

209-
# Add ``hoverxref`` role replicating the behavior of ``ref``
210-
app.add_role_to_domain(
211-
'std',
212-
'hoverxref',
213-
XRefRole(
214-
lowercase=True,
215-
innernodeclass=nodes.inline,
216-
warn_dangling=True,
217-
),
218-
)
219-
220-
app.add_domain(HoverXRefStandardDomain, override=True)
221-
app.add_domain(HoverXRefPythonDomain, override=True)
222-
227+
app.connect('config-inited', setup_domains)
223228
app.connect('build-finished', copy_asset_files)
224229

225230
for f in ASSETS_FILES:

tests/test_htmltag.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ def test_custom_object(app, status, warning):
178178

179179
@pytest.mark.sphinx(
180180
srcdir=pythondomainsrcdir,
181-
confoverrides={},
181+
confoverrides={
182+
'hoverxref_domains': ['py'],
183+
},
182184
)
183185
def test_python_domain(app, status, warning):
184186
app.build()

0 commit comments

Comments
 (0)