Skip to content
This repository was archived by the owner on Apr 9, 2025. It is now read-only.

Commit 6ca6dfd

Browse files
committed
Allow to specify the tooltip's type for each intersphinx role
Similiar to `hoverxref_types` but for each intersphinx mapping.
1 parent 26c1476 commit 6ca6dfd

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

docs/configuration.rst

+12-3
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,25 @@ These settings are global and have effect on both, tooltips and modal dialogues.
110110

111111
Default: ``{}``. It uses :confval:`hoverxref_default_type` if the intersphinx target is not defined in this config.
112112

113-
Type: str
113+
Type: dict
114114

115115
Example:
116116

117117
.. code-block:: python
118118
119119
{
120-
'readthdocs': 'modal',
120+
# make specific links to use a particular tooltip type
121+
'readthdocs': {
122+
'doc': 'modal',
123+
'ref': 'tooltip',
124+
},
125+
'python': {
126+
'class': 'modal',
127+
'ref':, 'tooltip',
128+
},
129+
130+
# make all links for Sphinx to be ``tooltip``
121131
'sphinx': 'tooltip',
122-
'python': 'tooltip',
123132
}
124133
125134
.. confval:: hoverxref_sphinxtabs

hoverxref/extension.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,12 @@ def missing_reference(app, env, node, contnode):
233233

234234
newnode = sphinx_missing_reference(app, env, node, contnode)
235235
if newnode is not None and not skip_node:
236-
hoverxref_type = app.config.hoverxref_intersphinx_types.get(inventory_name_matched) or app.config.hoverxref_default_type
236+
hoverxref_type = app.config.hoverxref_intersphinx_types.get(inventory_name_matched)
237+
if isinstance(hoverxref_type, dict):
238+
# Specific style for a particular reftype
239+
hoverxref_type = hoverxref_type.get(reftype)
240+
hoverxref_type = hoverxref_type or app.config.hoverxref_default_type
241+
237242
classes = newnode.get('classes')
238243
classes.extend(['hoverxref', hoverxref_type])
239244
newnode.replace_attr('classes', classes)

tests/test_htmltag.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ def test_intersphinx_python_mapping(app, status, warning):
276276
],
277277
'hoverxref_intersphinx_types': {
278278
'readthedocs': 'modal',
279+
'python': {
280+
'class': 'modal',
281+
}
279282
},
280283
'hoverxref_domains': ['py'],
281284
},
@@ -290,7 +293,7 @@ def test_intersphinx_all_mappings(app, status, warning):
290293
# Python's links do have hoverxref enabled
291294
'<a class="hoverxref tooltip reference external" data-url="https://docs.python.org/3/tutorial/index.html#tutorial-index" href="https://docs.python.org/3/tutorial/index.html#tutorial-index" title="(in Python v3.9)"><span class="xref std std-ref">This a :ref: to The Python Tutorial using intersphinx</span></a>',
292295
'<a class="hoverxref tooltip reference external" data-url="https://docs.python.org/3/library/datetime.html#datetime-datetime" href="https://docs.python.org/3/library/datetime.html#datetime-datetime" title="(in Python v3.9)"><span class="xref std std-ref">This a :ref: to datetime.datetime Python’s function using intersphinx</span></a>',
293-
'<a class="hoverxref tooltip reference external" data-url="https://docs.python.org/3/library/functions.html#float" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>',
296+
'<a class="hoverxref modal reference external" data-url="https://docs.python.org/3/library/functions.html#float" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>',
294297

295298
# Read the Docs' link does have hoverxref enabled
296299
'<a class="hoverxref modal reference external" data-url="https://docs.readthedocs.io/en/stable/config-file/v2.html#python" href="https://docs.readthedocs.io/en/stable/config-file/v2.html#python" title="(in Read the Docs v5.17.0)"><span class="xref std std-ref">This a :ref: to Config File v2 Read the Docs’ page using intersphinx</span></a>',

0 commit comments

Comments
 (0)