Skip to content

Commit bb0a656

Browse files
fix: align MyST heading slugs with docutils section IDs (#550)
MyST's default slug function uses GitHub-style heading IDs that preserve leading digits ("3.3 Toolchain Management" -> "33-toolchain-management"), but Sphinx section IDs are generated by docutils' make_id which strips them ("toolchain-management"). This mismatch causes spurious myst.xref_missing warnings on valid [text](file.md#anchor) cross- references whenever a heading starts with a numeric prefix. Set myst_heading_slug_func to docutils.nodes.make_id so both sides agree. Also enable myst_heading_anchors=4 so MyST can resolve heading cross-references up to h4 depth. Both settings use config_setdefault, so projects can still override them in their own conf.py.
1 parent 1a1cd79 commit bb0a656

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/extensions/score_sphinx_bundle/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ def setup(app: Sphinx) -> dict[str, object]:
6464
for e in score_extensions:
6565
app.setup_extension(e)
6666

67+
# Enable cross-reference resolution for [text](file.md#anchor) links up to h4.
68+
# Without this, MyST treats heading anchors as opaque and cannot resolve them.
69+
config_setdefault(app.config, "myst_heading_anchors", 4)
70+
71+
# MyST's default slug function uses GitHub-style heading IDs that keep leading
72+
# digits ("3.3 Toolchain Management" -> "33-toolchain-management"), but docutils'
73+
# make_id strips them ("toolchain-management"). Since Sphinx section IDs are
74+
# generated by docutils, the two algorithms disagree whenever a heading starts
75+
# with a numeric prefix, causing myst.xref_missing warnings on valid cross-
76+
# references. Aligning MyST's slug function on make_id fixes the mismatch.
77+
config_setdefault(app.config, "myst_heading_slug_func", "docutils.nodes.make_id")
78+
6779
# enable "..."-syntax in markdown — must come after myst_parser is loaded above
6880
if isinstance(app.config.myst_enable_extensions, list):
6981
app.config.myst_enable_extensions.append("colon_fence")

0 commit comments

Comments
 (0)