Skip to content

Commit 1deb83b

Browse files
committed
Use hoverxref_roles config to define which roles show tooltip
1 parent ccf4034 commit 1deb83b

File tree

5 files changed

+15
-79
lines changed

5 files changed

+15
-79
lines changed

docs/conf.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060

6161
hoverxref_tooltip_maxwidth = 650
6262
hoverxref_auto_ref = True
63+
hoverxref_roles = [
64+
'confval',
65+
]
6366
hoverxref_domains = [
6467
'py',
6568
]
@@ -204,19 +207,8 @@
204207

205208

206209
def setup(app):
207-
from hoverxref.nodeparser import parse_node
208210
app.add_object_type(
209211
'confval', # directivename
210212
'confval', # rolename
211213
'pair: %s; configuration value', # indextemplate
212-
parse_node=parse_node('confval'),
213214
)
214-
215-
# Remove ``update_contenxt`` from ``sphinx-tabs`` since it removes the
216-
# CSS/JS from pages that does not use the directive. Although, we need them
217-
# to use inside the tooltip.
218-
import inspect
219-
for listener_id, function in app.events.listeners.get('html-page-context').items():
220-
module_name = inspect.getmodule(function).__name__
221-
if module_name == 'sphinx_tabs.tabs':
222-
app.disconnect(listener_id)

docs/configuration.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ For more specific use cases, you can customize these configuration options in yo
4848

4949
Type: list
5050

51+
.. confval:: hoverxref_roles
52+
53+
Description: List containing roles where ``hoverxref`` has to be applied.
54+
55+
Default: ``[]``
56+
57+
Type: list
58+
5159
.. confval:: hoverxref_tooltip_class
5260

5361
Description: CSS class to add to ``div`` created for the tooltip

docs/usage.rst

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,15 @@ This will :hoverxref:`show a tooltip <hoverxref:section>` in the linked words to
2222
Tooltip on custom object
2323
------------------------
2424

25-
Sphinx has the ability to define custom objects via `Sphinx.add_object_type`_.
25+
Sphinx has the ability to define custom objects (via `Sphinx.add_object_type`_).
2626
``hoverxref`` can also show a tooltip on these objects if desired.
27-
To do that, when calling ``add_object_type`` you have to pass a specific function to ``parse_node`` argument.
28-
Let's say that we want to define a custom role and directive called ``confval``.
29-
In this case, calling ``Sphinx.add_object_type`` will look like:
30-
31-
.. code-block:: python
32-
:emphasize-lines: 10
33-
34-
# conf.py
35-
36-
def setup(app):
37-
# ...
38-
from hoverxref.nodeparser import parse_node
39-
app.add_object_type(
40-
'confval', # directivename
41-
'confval', # rolename
42-
'pair: %s; configuration value', # indextemplate
43-
parse_node=parse_node('confval'),
44-
)
45-
46-
Once the object is added, ``hoverxref`` will know that we want to add tooltips on these objects.
47-
48-
.. warning::
49-
50-
This ``parse_node`` argument with a custom function may not be required in the near future.
51-
27+
You need to tell ``hoverxref`` which are the roles where the tooltip has to appear on.
28+
To do this, use `:confval:hoverxref_roles` config.
5229

5330
Example
5431
~~~~~~~
5532

56-
This documentation defines the ``confval`` role as described above.
33+
This documentation defines the ``confval`` role.
5734
The role is used to define all the configurations of the extension.
5835
These configurations are added to the Sphinx index and we can easily refer to them and show a tooltip.
5936
This is reStructuredText code to do this:

hoverxref/nodeparser.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

hoverxref/registry.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)