Skip to content

Commit 911fb82

Browse files
committed
✨ NEW: Add tippy_add_class option
1 parent a9b5106 commit 911fb82

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

docs/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,29 @@ tippy_props = {"placement": "auto-start", "maxWidth": 500, "interactive": False,
100100
Note, only the `placement`, `maxWidth` and `interactive` props are allowed to be overridden currently.
101101
:::
102102

103+
:::{confval} tippy_add_class
104+
Add a class name to all elements with tips.
105+
106+
For example this can be used to change the style of the cursor when hovering over a tip (see [`html_css_files`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_css_files)):
107+
108+
`conf.py`:
109+
110+
```python
111+
html_static_path = ['_static']
112+
html_css_files = ["tippy.css"]
113+
tippy_add_class = "has-tippy"
114+
```
115+
116+
`_static/tippy.css`:
117+
118+
```css
119+
.has-tippy:hover {
120+
cursor: help;
121+
}
122+
```
123+
124+
:::
125+
103126
### Filters
104127

105128
These configurations enable filtering of what tips are created, and shown.

src/sphinx_tippy.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
except ImportError:
2626
from sphinx.util import status_iterator
2727

28-
__version__ = "0.4.0"
28+
__version__ = "0.4.1"
2929

3030

3131
def setup(app: Sphinx):
@@ -80,6 +80,7 @@ def setup(app: Sphinx):
8080
"html",
8181
[list, tuple],
8282
)
83+
app.add_config_value("tippy_add_class", "", "html")
8384

8485
app.connect("builder-inited", compile_config)
8586
app.connect("html-page-context", collect_tips, priority=450) # before mathjax
@@ -105,6 +106,7 @@ class TippyConfig:
105106
doi_template: str
106107
doi_api: str
107108
js_files: tuple[str, ...]
109+
tippy_add_class: str
108110

109111

110112
def get_tippy_config(app: Sphinx) -> TippyConfig:
@@ -171,6 +173,7 @@ def compile_config(app: Sphinx):
171173
doi_template=app.config.tippy_doi_template,
172174
doi_api=app.config.tippy_doi_api,
173175
js_files=app.config.tippy_js,
176+
tippy_add_class=app.config.tippy_add_class,
174177
)
175178
if app.builder.name != "html":
176179
return
@@ -693,8 +696,10 @@ def write_tippy_props_page(
693696
# TODO need to only enable when math,
694697
# and then need to ensure sphinx adds mathjax to the page
695698

699+
tippy_add_class = ""
700+
if tippy_config.tippy_add_class:
701+
tippy_add_class = f"link.classList.add({tippy_config.tippy_add_class!r});"
696702
tippy_props = ", ".join(f"{k}: {v}" for k, v in tippy_config.props.items())
697-
698703
content = (
699704
dedent(
700705
f"""\
@@ -708,6 +713,7 @@ def write_tippy_props_page(
708713
if (skip_classes.some(c => link.classList.contains(c))) {{
709714
continue;
710715
}}
716+
{tippy_add_class}
711717
tippy(link, {{
712718
content: tip_html,
713719
allowHTML: true,

0 commit comments

Comments
 (0)