Skip to content

Commit f856160

Browse files
authored
feat: Add data-skip-inventory boolean attribute for elements to skip registration in local inventory
Issue-671: #671 PR-774: #774
1 parent 2b4ed54 commit f856160

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/mkdocstrings/_internal/extension.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ def _process_headings(self, handler: BaseHandler, element: Element) -> None:
251251

252252
for heading in headings:
253253
rendered_id = heading.attrib["id"]
254+
255+
skip_inventory = "data-skip-inventory" in heading.attrib
256+
if skip_inventory:
257+
_logger.debug(
258+
"Skipping heading with id %r because data-skip-inventory is present",
259+
rendered_id,
260+
)
261+
continue
262+
254263
# The title is registered to be used as tooltip by autorefs.
255264
self._autorefs.register_anchor(page, rendered_id, title=heading.text, primary=True)
256265

src/mkdocstrings/_internal/handlers/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ def do_heading(
459459
role: str | None = None,
460460
hidden: bool = False,
461461
toc_label: str | None = None,
462+
skip_inventory: bool = False,
462463
**attributes: str,
463464
) -> Markup:
464465
"""Render an HTML heading and register it for the table of contents. For use inside templates.
@@ -469,6 +470,7 @@ def do_heading(
469470
role: An optional role for the object bound to this heading.
470471
hidden: If True, only register it for the table of contents, don't render anything.
471472
toc_label: The title to use in the table of contents ('data-toc-label' attribute).
473+
skip_inventory: Flag element to not be registered in the inventory (by setting a `data-skip-inventory` attribute).
472474
**attributes: Any extra HTML attributes of the heading.
473475
474476
Returns:
@@ -488,6 +490,8 @@ def do_heading(
488490
if toc_label is None:
489491
toc_label = content.unescape() if isinstance(content, Markup) else content
490492
el.set("data-toc-label", toc_label)
493+
if skip_inventory:
494+
el.set("data-skip-inventory", "true")
491495
if role:
492496
el.set("data-role", role)
493497
if content:

0 commit comments

Comments
 (0)