Skip to content

Commit 6d79791

Browse files
committed
✨ NEW: Add ReadTheDocs API tips
Plus more configuration: tippy_props, tippy_skip_urls
1 parent c51c32e commit 6d79791

File tree

7 files changed

+221
-43
lines changed

7 files changed

+221
-43
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ repos:
3333
- docutils-stubs
3434
- sphinx~=5.0
3535
- types-beautifulsoup4
36+
- types-requests
3637
files: >
3738
(?x)^(
3839
src/.*py|

docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
"and menu solution for the web, powered by Popper.</p>"
4040
),
4141
}
42+
tippy_rtd_urls = [
43+
"https://www.sphinx-doc.org/en/master/",
44+
"https://docs.readthedocs.io/en/stable/",
45+
]
4246

4347

4448
def setup(app):

docs/index.md

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Now your website will have tooltips on many of your links!
3636

3737
- - [DOI tip](https://doi.org/10.1186/gm483)
3838

39+
- - [ReadTheDocs tip](https://www.sphinx-doc.org/en/master/usage/quickstart.html#intersphinx)
40+
3941
- - {ref}`Figure reference with URL image <figure-name-url>`
4042

4143
- - {ref}`Figure reference with local image <figure-name-file>`
@@ -80,22 +82,34 @@ Currently, all tips are created during the build process, so there is no need fo
8082
The internal tips are created simply by "scraping" the built HTML, which bypasses having to deal with the sphinx internals, like domains etc.
8183

8284
Note, there is another sphinx extension for hover tips; [sphinx-hoverxref](https://github.com/readthedocs/sphinx-hoverxref),
83-
however, one of the annoyances with this is that documentation has to be hosted on Read the Docs for it to work.
84-
It does though have some nice features, like tooltips for intersphinx, which we would like here.
85+
however, one of the annoyances with this is that documentation has to be hosted on Read the Docs for it to work, since that used the RTD embed API dynamically.
8586

8687
## Configuration
8788

88-
The extension has the following configuration options:
89+
The extension has the following configuration options.
8990

90-
:::{confval} tippy_custom_tips
91-
A dictionary, mapping URLs to HTML strings, which will be used to create custom tips.
91+
## Display
9292

93-
For example, to add a tip for the URL `https://example.com`:
93+
:::{confval} tippy_props
94+
Overrides for the [tippy.js props](https://atomiks.github.io/tippyjs/v6/all-props/) to use, by default:
9495

9596
```python
96-
tippy_custom_tips = {
97-
"https://example.com": "<p>This is a custom tip!</p>"
98-
}
97+
tippy_props = {"placement": "auto-start", "maxWidth": 500, "interactive": False, "arrow": True}
98+
```
99+
100+
Note, only the `placement`, `maxWidth` and `interactive` props are allowed to be overridden currently.
101+
102+
### Filters
103+
104+
These configurations enable filtering of what tips are created, and shown.
105+
106+
:::{confval} tippy_skip_urls
107+
A list of URL [regexes](https://docs.python.org/3/howto/regex.html#regex-howto) to skip, for example:
108+
109+
```python
110+
tippy_skip_urls = [
111+
"https://example.com/name_prefix.*",
112+
]
99113
```
100114

101115
:::
@@ -110,7 +124,7 @@ tippy_tip_selector = "figure, table, img, p, aside, div.admonition, div.literal-
110124
:::
111125

112126
:::{confval} tippy_skip_anchor_classes
113-
Skip creating tooltips for anchors with these classes, by default:
127+
Skip showing tooltips for anchors with these classes, by default:
114128

115129
```python
116130
tippy_skip_anchor_classes = (
@@ -122,7 +136,7 @@ tippy_skip_anchor_classes = (
122136
:::
123137

124138
:::{confval} tippy_anchor_parent_selector
125-
Only create tool tips for anchors within this select, by default `""`, examples:
139+
Only show tool tips for anchors within this select, by default `""`, examples:
126140

127141
```python
128142
# For Furo theme:
@@ -133,6 +147,24 @@ tippy_anchor_parent_selector = "article.bd-article"
133147

134148
:::
135149

150+
### External APIs
151+
152+
These configurations enable fetching tips from external APIs.
153+
154+
:::{confval} tippy_rtd_urls
155+
A list of URL prefixes to use for ReadTheDocs tooltips (using the [`/api/v3/embed/` API](https://docs.readthedocs.io/en/stable/api/v3.html#embed)), for example:
156+
157+
```python
158+
tippy_rtd_urls = [
159+
"https://www.sphinx-doc.org/en/master/",
160+
]
161+
```
162+
163+
This works for any ReadTheDocs hosted documentation.
164+
It works well with the [intersphinx extension](https://www.sphinx-doc.org/en/master/usage/quickstart.html#intersphinx).
165+
166+
:::
167+
136168
:::{confval} tippy_enable_wikitips
137169
Enable tooltips for wikipedia links, starting `https://en.wikipedia.org/wiki/`, by default `True`.
138170
:::
@@ -164,6 +196,22 @@ The [jinja template](https://jinja.palletsprojects.com) to use for formatting DO
164196
(See <https://github.com/CrossRef/rest-api-doc/blob/master/api_format.md>)
165197
:::
166198

199+
200+
### Miscellaneous
201+
202+
:::{confval} tippy_custom_tips
203+
A dictionary, mapping URLs to HTML strings, which will be used to create custom tips.
204+
205+
For example, to add a tip for the URL `https://example.com`:
206+
207+
```python
208+
tippy_custom_tips = {
209+
"https://example.com": "<p>This is a custom tip!</p>"
210+
}
211+
```
212+
213+
:::
214+
167215
:::{confval} tippy_enable_mathjax
168216
Whether to enable tooltips for math equations, by default `False`.
169217

docs/tippy-logo.svg

Lines changed: 1 addition & 1 deletion
Loading

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies = [
2121
"sphinx>4",
2222
"beautifulsoup4",
2323
"jinja2",
24+
"requests",
2425
]
2526

2627
[project.urls]

0 commit comments

Comments
 (0)