Skip to content

fix: align MyST heading slugs with docutils section IDs#550

Open
AlexanderLanin wants to merge 1 commit into
eclipse-score:mainfrom
etas-contrib:fix/myst-heading-slug-alignment
Open

fix: align MyST heading slugs with docutils section IDs#550
AlexanderLanin wants to merge 1 commit into
eclipse-score:mainfrom
etas-contrib:fix/myst-heading-slug-alignment

Conversation

@AlexanderLanin
Copy link
Copy Markdown
Member

Summary

  • Set myst_heading_slug_func = "docutils.nodes.make_id" as a bundle default so MyST's cross-reference resolver and docutils' section ID generator use the same algorithm
  • Set myst_heading_anchors = 4 as a bundle default so [text](file.md#anchor) links resolve up to h4 depth
  • Both use config_setdefault, so projects can still override in their own conf.py

Problem

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 causes spurious myst.xref_missing warnings on valid [text](file.md#anchor) cross-references whenever a heading starts with a numeric prefix.

The bug only surfaces when headings have leading numbers (e.g. numbered chapters), which is why most projects never notice.

Test plan

  • Existing tests pass
  • Build documentation for a project with numbered headings and [text](file.md#anchor) cross-references — verify no myst.xref_missing warnings

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.
@github-actions
Copy link
Copy Markdown

License Check Results

🚀 The license check job ran with the Bazel command:

bazel run --lockfile_mode=error //src:license-check

Status: ⚠️ Needs Review

Click to expand output
[License Check Output]
Extracting Bazel installation...
Starting local Bazel server (8.6.0) and connecting to it...
INFO: Invocation ID: b95e23c6-3e93-444b-aec0-93360b0555b4
Computing main repo mapping: 
Loading: 
Loading: 0 packages loaded
Loading: 0 packages loaded
WARNING: Target pattern parsing failed.
ERROR: Skipping '//src:license-check': no such target '//src:license-check': target 'license-check' not declared in package 'src' defined by /home/runner/work/docs-as-code/docs-as-code/src/BUILD
ERROR: no such target '//src:license-check': target 'license-check' not declared in package 'src' defined by /home/runner/work/docs-as-code/docs-as-code/src/BUILD
INFO: Elapsed time: 4.837s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target

@github-actions
Copy link
Copy Markdown

The created documentation from the pull request is available at: docu-html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant