You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add link_titles option and adapt related logic
This change adds a `link_titles` option that defaults to `"auto"`. In automatic mode, link titles are either:
- always set if Material for MkDocs and its instant preview feature aren't detected
- only set on external links otherwise (since instant preview are not supported on external links anyway)
The option also accepts the `True` and `False`, for always/never setting titles, respectively.
An update to the title logic accompanies this change in order to make use of recorded heading titles (a change brought two commit ago):
- optional cross-references will use the original title, and optionally append the identifier if it doesn't already appear in the title
- mandatory cross-references will use either the original title if there's one, or no title at all
This is because optional cross-refs are almost exclusively created by mkdocstrings handlers, and therefore displaying the identifier (full qualified name of objects) is useful when hovering on a link. Manual cross-references on the other hand can often be references to text sections, and should never display the section anchor. The limitation being that manual cross-references to API objects won't show the identifier. We could consider using an additional attribute (other than `optional`) to label cross-refs as "API objects" or not, though users would still have to annotate their manual cross-refs with such an attribute to enjoy the appended identifier to the title.
Issue-33: #33
Issue-62: #62
Copy file name to clipboardExpand all lines: README.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -182,3 +182,22 @@ You can also change the actual identifier of a heading, thanks again to the `att
182
182
```
183
183
184
184
...though note that this will impact the URL anchor too (and therefore the permalink to the heading).
185
+
186
+
### Link titles
187
+
188
+
When rendering cross-references, the autorefs plugin sets `title` HTML attributes on links. These titles are displayed as tooltips when hovering on links. For mandatory cross-references (user-written ones), the original title of the target section is used as tooltip, for example: `Original title`. For optional cross-references (typically rendered by mkdocstrings handlers), the identifier is appended to the original title, for example: `Original title (package.module.function)`. This is useful to indicate the fully qualified name of API objects.
189
+
190
+
Since the presence of titles prevents [the instant preview feature of Material for MkDocs][instant-preview] from working, the autorefs plugin will detect when this theme and feature are used, and only set titles on *external* links (for which instant previews cannot work).
191
+
192
+
If you want to force autorefs to always set titles, never set titles, or only set titles on external links, you can use the `link_titles` option:
0 commit comments