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
Copy file name to clipboardexpand all lines: README.md
+42-2
Original file line number
Diff line number
Diff line change
@@ -47,9 +47,38 @@ We can [link to that heading][hello-world] from another page too.
47
47
This works the same as [a normal link to that heading](../doc1.md#hello-world).
48
48
```
49
49
50
-
Linking to a heading without needing to know the destination page can be useful if specifying that path is cumbersome, e.g. when the pages have deeply nested paths, are far apart, or are moved around frequently. And the issue is somewhat exacerbated by the fact that [MkDocs supports only *relative* links between pages](https://github.com/mkdocs/mkdocs/issues/1592).
50
+
Linking to a heading without needing to know the destination page can be useful if specifying that path is cumbersome, e.g. when the pages have deeply nested paths, are far apart, or are moved around frequently.
51
51
52
-
Note that this plugin's behavior is undefined when trying to link to a heading title that appears several times throughout the site. Currently it arbitrarily chooses one of the pages. In such cases, use [Markdown anchors](#markdown-anchors) to add unique aliases to your headings.
52
+
### Non-unique headings
53
+
54
+
When linking to a heading that appears several times throughout the site, this plugin will log a warning message stating that multiple URLs were found and that headings should be made unique, and will resolve the link using the first found URL.
55
+
56
+
To prevent getting warnings, use [Markdown anchors](#markdown-anchors) to add unique aliases to your headings, and use these aliases when referencing the headings.
57
+
58
+
If you cannot use Markdown anchors, for example because you inject the same generated contents in multiple locations (for example mkdocstrings' API documentation), then you can try to alleviate the warnings by enabling the `resolve_closest` option:
59
+
60
+
```yaml
61
+
plugins:
62
+
- autorefs:
63
+
resolve_closest: true
64
+
```
65
+
66
+
When `resolve_closest` is enabled, and multiple URLs are found for the same identifier, the plugin will try to resolve to the one that is "closest" to the current page (the page containing the link). By closest, we mean:
67
+
68
+
- URLs that are relative to the current page's URL, climbing up parents
69
+
- if multiple URLs are relative to it, use the one at the shortest distance if possible.
70
+
71
+
If multiple relative URLs are at the same distance, the first of these URLs will be used. If no URL is relative to the current page's URL, the first URL of all found URLs will be used.
72
+
73
+
Examples:
74
+
75
+
Current page | Candidate URLs | Relative URLs | Winner
0 commit comments