From 7b8240047b2ec1ade9bb987a8780a9ed6ce18cef Mon Sep 17 00:00:00 2001 From: Tim Paine <3105306+timkpaine@users.noreply.github.com> Date: Fri, 4 Sep 2026 17:43:53 -0400 Subject: [PATCH] Track AutoAPI anchors in page TOC Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com> --- sphinx_fuma/static/fuma.js | 2 +- sphinx_fuma/tests/test_theme.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sphinx_fuma/static/fuma.js b/sphinx_fuma/static/fuma.js index 729b63f..0e4426a 100644 --- a/sphinx_fuma/static/fuma.js +++ b/sphinx_fuma/static/fuma.js @@ -163,7 +163,7 @@ .map(function (item) { var href = item.querySelector("a").getAttribute("href") || ""; var anchor = href.charAt(0) === "#" ? document.getElementById(decodeURIComponent(href.slice(1))) : null; - var heading = anchor && (anchor.matches("h1, h2, h3, h4, h5, h6") ? anchor : anchor.querySelector("h1, h2, h3, h4, h5, h6")); + var heading = anchor && (anchor.matches("h1, h2, h3, h4, h5, h6") ? anchor : anchor.querySelector("h1, h2, h3, h4, h5, h6") || anchor); return heading ? { item: item, heading: heading } : null; }) .filter(Boolean); diff --git a/sphinx_fuma/tests/test_theme.py b/sphinx_fuma/tests/test_theme.py index 8238f00..2c28f4e 100644 --- a/sphinx_fuma/tests/test_theme.py +++ b/sphinx_fuma/tests/test_theme.py @@ -208,6 +208,7 @@ def test_toc_rail_is_an_svg_with_track_and_thumb(self, built): def test_toc_scroll_spy_observes_headings_across_the_viewport(self, built): script = (built / "_static" / "fuma.js").read_text() assert 'anchor.querySelector("h1, h2, h3, h4, h5, h6")' in script + assert 'anchor.querySelector("h1, h2, h3, h4, h5, h6") || anchor' in script assert "threshold: 0.9" in script assert "rootMargin:" not in script