Skip to content

Commit

Permalink
feat: Register objects' aliases into the inventory
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pawamoy committed Jul 17, 2023
1 parent 433c6e0 commit ee93e80
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/mkdocstrings/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit ee93e80

Please sign in to comment.