diff --git a/tests/test_badge_tooltips.py b/tests/test_badge_tooltips.py
index 57d505a7..7e2bb73d 100644
--- a/tests/test_badge_tooltips.py
+++ b/tests/test_badge_tooltips.py
@@ -22,6 +22,8 @@
reStructuredText, and the MyST variants are guarded by ``MYST_PARAM``.
"""
+import re
+
from docutils import nodes
import pytest
from sphinx import addnodes
@@ -349,8 +351,15 @@ def test_ref_badge_tooltip_survives_resolution(fmt, sphinx_builder):
builder = _build(sphinx_builder, fmt, REF["rst"], REF["myst"])
html = (builder.out_path / "index.html").read_text(encoding="utf8")
- # both badges resolve to the target anchor
- assert html.count('href="#my-target"') == 2
+ # both badges resolve to the target anchor; only the badge anchors are
+ # counted, since the theme's own links to the section (its headerlink,
+ # the sidebar TOC) depend on which id the parser makes the section's
+ # primary one, and MyST-Parser's heading-anchor rework
+ # (executablebooks/MyST-Parser#1158) makes it the explicit target
+ badge_anchors = re.findall(
+ r']', html
+ )
+ assert len(badge_anchors) == 2
# the tooltipped one carries the title; it survived resolution
assert (
' 1:
+ node["ids"] = sorted(node["ids"])
+ return doctree
+
+
def write_assets(src_path: Path):
"""Write additional assets to the src directory."""
src_path.joinpath("snippet.py").write_text("a = 1")
@@ -50,7 +66,7 @@ def test_snippets_rst(
builder.src_path.joinpath("index.rst").write_text(content, encoding="utf8")
write_assets(builder.src_path)
builder.build()
- doctree = builder.get_doctree("index", post_transforms=False)
+ doctree = sort_ids(builder.get_doctree("index", post_transforms=False))
doctree.attributes.pop("translation_progress", None) # added in sphinx 7.1
file_regression.check(
normalize_doctree_xml(doctree.pformat()),
@@ -78,7 +94,7 @@ def test_snippets_myst(
builder.src_path.joinpath("index.md").write_text(content, encoding="utf8")
write_assets(builder.src_path)
builder.build()
- doctree = builder.get_doctree("index", post_transforms=False)
+ doctree = sort_ids(builder.get_doctree("index", post_transforms=False))
doctree.attributes.pop("translation_progress", None) # added in sphinx 7.1
file_regression.check(
normalize_doctree_xml(doctree.pformat()),
@@ -105,7 +121,7 @@ def test_snippets_rst_post(
builder.src_path.joinpath("index.rst").write_text(content, encoding="utf8")
write_assets(builder.src_path)
builder.build()
- doctree = builder.get_doctree("index", post_transforms=True)
+ doctree = sort_ids(builder.get_doctree("index", post_transforms=True))
doctree.attributes.pop("translation_progress", None) # added in sphinx 7.1
file_regression.check(
normalize_doctree_xml(doctree.pformat()),
@@ -133,7 +149,7 @@ def test_snippets_myst_post(
builder.src_path.joinpath("index.md").write_text(content, encoding="utf8")
write_assets(builder.src_path)
builder.build()
- doctree = builder.get_doctree("index", post_transforms=True)
+ doctree = sort_ids(builder.get_doctree("index", post_transforms=True))
doctree.attributes.pop("translation_progress", None) # added in sphinx 7.1
file_regression.check(
normalize_doctree_xml(doctree.pformat()),
diff --git a/tests/test_snippets/snippet_post_card-link.xml b/tests/test_snippets/snippet_post_card-link.xml
index 3d74e127..59ec5e47 100644
--- a/tests/test_snippets/snippet_post_card-link.xml
+++ b/tests/test_snippets/snippet_post_card-link.xml
@@ -3,7 +3,7 @@
Heading
-
+
Clickable cards
diff --git a/tests/test_snippets/snippet_pre_card-link.xml b/tests/test_snippets/snippet_pre_card-link.xml
index 86461813..2f7b35bf 100644
--- a/tests/test_snippets/snippet_pre_card-link.xml
+++ b/tests/test_snippets/snippet_pre_card-link.xml
@@ -3,7 +3,7 @@
Heading
-