-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Backlinks #65
Merged
feat: Backlinks #65
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pawamoy
commented
Feb 19, 2025
pawamoy
commented
Feb 20, 2025
dec902a
to
b566031
Compare
pawamoy
added a commit
that referenced
this pull request
Feb 23, 2025
This feature only allows recording and retrieving backlinks, for other plugins or systems to render them. Backlinks are not rendered directly by autorefs (though we could consider offering such a feature in the future). PR-65: #65 Issue-mkdocstrings-723: mkdocstrings/mkdocstrings#723 Issue-mkdocstrings-python-153: mkdocstrings/python#153
This change makes autorefs record heading titles alongside URLs, but doesn't actually change the rendering logic. This will be done in a later change that will rely on new title-related options. Issue-33: #33
Previously, we used the `on_post_page` hook to fix cross-references. This was problematic because it cornered us to the last per-page event, making it difficult to coordinate ourselves with other plugins such as mkdocstrings. Fixing cross-references must be done once all pages have been rendered to HTML. The earliest we can do that is in `on_env`, which acts as a synchronization barrier here. We coordinate the logic with mkdocstrings thanks to event priorities: autorefs' `on_env` must run after mkdocstrings has finished loading inventories, so that all cross-references can be fixed. Since mkdocstrings uses the default priority, 0, our -50 priority makes us run last. Discussion-mkdocs-3917: mkdocs/mkdocs#3917
pawamoy
added a commit
that referenced
this pull request
Feb 23, 2025
This feature only allows recording and retrieving backlinks, for other plugins or systems to render them. Backlinks are not rendered directly by autorefs (though we could consider offering such a feature in the future). PR-65: #65 Issue-mkdocstrings-723: mkdocstrings/mkdocstrings#723 Issue-mkdocstrings-python-153: mkdocstrings/python#153
pawamoy
added a commit
that referenced
this pull request
Feb 23, 2025
This feature only allows recording and retrieving backlinks, for other plugins or systems to render them. Backlinks are not rendered directly by autorefs (though we could consider offering such a feature in the future). PR-65: #65 Issue-mkdocstrings-723: mkdocstrings/mkdocstrings#723 Issue-mkdocstrings-python-153: mkdocstrings/python#153
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
The plugin records heading titles, and sets them as `title` attribute of cross-references (HTML links). Sometimes these titles contain HTML, and some MkDocs themes do not support HTML in them (they are shown as tooltips when hovering on links). This option allows to strip tags (while keeping text) from titles. When set to `"auto"` (default value), it only strips tags for unsupported themes (all except Material for MkDocs). Issue-33: #33
…ent_page` attribute We will need the page instance for the backlinks feature, to build breadcrumbs with titles and URLs of the parents of each backlink.
This feature only allows recording and retrieving backlinks, for other plugins or systems to render them. Backlinks are not rendered directly by autorefs (though we could consider offering such a feature in the future). PR-65: #65 Issue-mkdocstrings-723: mkdocstrings/mkdocstrings#723 Issue-mkdocstrings-python-153: mkdocstrings/python#153
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TODO:
scan_toc
)