Skip to content

Commit 4e1e37d

Browse files
committed
More flexibility for floating window styles
Use a dictionary to configure each role style: ref, confval, mod, class, etc
1 parent 7bf9552 commit 4e1e37d

File tree

6 files changed

+59
-7
lines changed

6 files changed

+59
-7
lines changed

docs/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
hoverxref_roles = [
6666
'confval',
6767
]
68+
69+
hoverxref_default_types = {
70+
'hoverxref': 'tooltip',
71+
'ref': 'modal',
72+
'confval': 'tooltip',
73+
'mod': 'modal',
74+
'class': 'modal',
75+
}
6876
hoverxref_domains = [
6977
'py',
7078
]

docs/configuration.rst

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,30 @@ General settings
1414

1515
These settings are global and have effect on both, tooltips and modal dialogues.
1616

17-
.. confval:: hoverxref_type
17+
.. confval:: hoverxref_default_types
1818

19-
Description: How to display the embedded content. As a Tooltip or as a Modal dialogue.
19+
Description: Style to use by default when for the embedded content when using ``:hoverxref:`` role.
20+
It also affect the style of and ``:ref:``
21+
22+
Default: ``{}``
23+
24+
Example:
25+
26+
.. code-block:: python
27+
28+
{
29+
'hoverxref': 'modal',
30+
'ref': 'modal',
31+
'confval': 'tooltip',
32+
'mod': 'tooltip', # for Python Domain
33+
'class': 'tooltip', # for Python Domain
34+
}
35+
36+
Type: dictionary
37+
38+
.. confval:: hoverxref_default_type
39+
40+
Description: Default style when the specific one was not found in :confval:`hoverxref_default_types`.
2041

2142
Default: ``tooltip``
2243

@@ -26,7 +47,7 @@ These settings are global and have effect on both, tooltips and modal dialogues.
2647

2748
.. confval:: hoverxref_auto_ref
2849

29-
Description: Make all ``:ref:`` role to show a tooltip
50+
Description: Make all ``:ref:`` role to show a tooltip.
3051

3152
Default: ``False``
3253

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ We currently support two different types of floating windows: Tooltip and Modal.
2727

2828
.. note::
2929

30-
The default style (tooltip or modal) is defined by the config :confval:`hoverxref_type <hoverxref_type>`.
30+
The default style (tooltip or modal) is defined by the config :confval:`hoverxref_default_types <hoverxref_default_types>`.
3131

3232

3333
.. tab:: Tooltip style

hoverxref/domains.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,28 @@ def _is_hoverxref_configured(self, env):
1818
return project and version
1919

2020
def _inject_hoverxref_data(self, env, refnode, typ, docname, docpath, labelid):
21-
type_class = 'tooltip' if typ == 'hoverxreftooltip' else ('modal' if typ == 'hoverxrefmodal' else env.config.hoverxref_default_type)
22-
refnode.replace_attr('classes', ['hoverxref', type_class])
21+
classes = ['hoverxref']
22+
type_class = None
23+
if typ == 'hoverxreftooltip':
24+
type_class = 'tooltip'
25+
classes.append(type_class)
26+
elif typ == 'hoverxrefmodal':
27+
type_class = 'modal'
28+
classes.append(type_class)
29+
if not type_class:
30+
type_class = env.config.hoverxref_default_types.get(typ)
31+
if not type_class:
32+
default = env.config.hoverxref_default_type
33+
type_class = default
34+
logger.warning(
35+
'Using default style for unknown typ. '
36+
'Define it in hoverxref_default_types. typ=%s style=%s',
37+
typ,
38+
default,
39+
)
40+
classes.append(type_class)
41+
42+
refnode.replace_attr('classes', classes)
2343

2444
project = env.config.hoverxref_project
2545
version = env.config.hoverxref_version

hoverxref/extension.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ def setup(app):
230230
app.add_config_value('hoverxref_sphinxtabs', False, 'env')
231231
app.add_config_value('hoverxref_roles', [], 'env')
232232
app.add_config_value('hoverxref_domains', [], 'env')
233+
234+
app.add_config_value('hoverxref_default_types', {}, 'env')
233235
app.add_config_value('hoverxref_default_type', 'tooltip', 'env')
236+
234237
app.add_config_value('hoverxref_api_host', 'https://readthedocs.org', 'env')
235238

236239
# Tooltipster settings

tests/test_htmltag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_python_domain(app, status, warning):
179179
'hoverxref_default_type': 'modal',
180180
},
181181
)
182-
def test_project_version_settings(app, status, warning):
182+
def test_default_types(app, status, warning):
183183
app.build()
184184
path = app.outdir / 'index.html'
185185
assert path.exists() is True

0 commit comments

Comments
 (0)