From ee93e80f904f213dd621e047ada3e51018c4b17d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Mon, 17 Jul 2023 16:45:13 +0200 Subject: [PATCH] feat: Register objects' aliases into the inventory When publishing API docs, maintainers might inject documentation for an object for only one of its locations (canonical, public, other alias, etc.). Without this change, other doc sites can only cross-reference this object with the path it was rendered with. With this change, other doc sites can cross-reference the object with any of its aliases. It means that doc writers do not have to worry about injecting docs for every object with both their canonical and public paths: only one path is fine, and other can cross-ref to it with any valid alias path. --- src/mkdocstrings/extension.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/mkdocstrings/extension.py b/src/mkdocstrings/extension.py index 3ee256f2..e5e2c507 100644 --- a/src/mkdocstrings/extension.py +++ b/src/mkdocstrings/extension.py @@ -135,16 +135,17 @@ def run(self, parent: Element, blocks: MutableSequence[str]) -> None: page = self._autorefs.current_page if page is not None: for heading in headings: - anchor = heading.attrib["id"] - self._autorefs.register_anchor(page, anchor) + rendered_anchor = heading.attrib["id"] + self._autorefs.register_anchor(page, rendered_anchor) if "data-role" in heading.attrib: - self._handlers.inventory.register( - name=anchor, - domain=handler.domain, - role=heading.attrib["data-role"], - uri=f"{page}#{anchor}", - ) + for anchor in sorted({rendered_anchor, *handler.get_anchors(data)}): + self._handlers.inventory.register( + name=anchor, + domain=handler.domain, + role=heading.attrib["data-role"], + uri=f"{page}#{rendered_anchor}", + ) parent.append(el)