Repository navigation
🐛 FIX: Preserve explicit heading anchor IDs - #159
Merged
chrisjsewell merged 7 commits intoNov 9, 2026
Merged
chrisjsewell merged 7 commits into
chrisjsewell merged 7 commits into
Conversation
An empty `{id=""}` is invalid HTML and gave a `href="#"` permalink;
it is now neither reserved nor kept, and the heading gets a generated id.
Tests pin the out-of-level reservation, duplicate explicit ids being kept
(no error), the empty id, and plugin load-order independence.
The default slug function no longer strips leading/trailing whitespace, so it is now identical to MyST-Parser's `github_slugify` (which keeps it deliberately, see its v0.18.1 changelog). This changes generated ids where the title text starts or ends with a space next to an image, raw HTML or an entity, e.g. `# Foo ` gives `foo-` (was `foo`), and `# &executablebooks#32;Foo` gives `-foo` (was `foo`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
attrs_block_pluginassigns a heading ID, the anchors plugin overwrites it with a slug of the title. This breaks explicit links and calls custom slug functions unnecessarily.Preserve existing heading IDs and use them for permalinks. Reserve explicit IDs before generating slugs so automatic headings avoid collisions regardless of their order in the document. Update the public docstring and changelog.
Four regressions fail before the change: an explicit ID, collisions before and after an explicit heading, and a custom slug function that must not run for an explicit ID.
Validation: the prescribed Tox Python 3.13 session passes all 515 tests. All repository pre-commit hooks pass, including pinned Ruff checks and strict Mypy.