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
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
Copy file name to clipboardexpand all lines: README.md
+94
Original file line number
Diff line number
Diff line change
@@ -211,3 +211,97 @@ plugins:
211
211
# strip_title_tags: true
212
212
# strip_title_tags: auto # default
213
213
```
214
+
215
+
### Backlinks
216
+
217
+
The autorefs plugin supports recording backlinks, that other plugins or systems can then use to render backlinks into pages.
218
+
219
+
For example, when linking from page `foo/`, section `Section` to a heading with identifier `heading` thanks to a cross-reference `[Some heading][heading]`, the plugin will record that `foo/#section` references `heading`.
220
+
221
+
```md
222
+
# Page foo
223
+
224
+
This is page foo.
225
+
226
+
## Section
227
+
228
+
This section references [some heading][heading].
229
+
```
230
+
231
+
The `record_backlinks` attribute of the autorefs plugin must be set to true before Markdown is rendered to HTML to enable backlinks recording. This is typically done in an `on_config` MkDocs hook:
Note that for backlinks to be recorded with accurate URLs, headings must have HTML IDs, meaning either the `toc` extension must be enabled, or the `attr_list` extension must be enabled *and* authors must add IDs to the relevant headings, with the `## Heading { #heading-id }` syntax.
243
+
244
+
Other plugins or systems integrating with the autorefs plugin can then retrieve backlinks for a specific identifier:
The `get_backlinks` method returns a map of backlink types to sets of backlinks. A backlink is a tuple of navigation breadcrumbs, each breadcrumb having a title and URL.
The default backlink type is `referenced-by`, but can be customized by other plugins or systems thanks to the `backlink-type` HTML data attribute on `autoref` elements. Such plugins and systems can also specify the anchor on the current page to use for the backlink with the `backlink-anchor` HTML data attribute on `autoref` elements.
This feature is typically designed for use in [mkdocstrings](https://mkdocstrings.github.io/) handlers, though is not exclusive to mkdocstrings: it can be used by any other plugin or even author hooks. Such a hook is provided as an example here:
0 commit comments