fix: build anchor macros for section titles containing special charac… - #1193
Open
blackduckx wants to merge 1 commit into
Open
fix: build anchor macros for section titles containing special charac…#1193blackduckx wants to merge 1 commit into
blackduckx wants to merge 1 commit into
Conversation
…ters
Section titles containing characters flagged as "unsafe" by ascii_quote()
(e.g. `&`) never received an `<ac:structured-macro ac:name="anchor">` in
the generated storage-format output, even though the heading text itself
rendered correctly.
The anchor target for a title is registered in
`_register_doctree_targets` (builder.py) keyed on the section's `ids`
(docutils' ascii-safe, punctuation-stripped slug), unconditionally. But
`visit_title` (storage/translator.py) looked that target up using a
different key, rebuilt from the section's `names` (which keeps
punctuation like `&`). For titles with no special characters both keys
happened to match; for a title like "Foo & Bar" they diverged
("foo-bar" vs "foo-&-bar"), the lookup silently returned nothing, and
the anchor macro was skipped entirely.
The fix makes `visit_title` key its lookup off the section's `ids`
directly, matching exactly what is registered, so the anchor is always
found regardless of the title's characters.
Adds a regression test (dataset + test case) covering a section title
with an ampersand, including its local table-of-contents backlink.
Signed-off-by: Frédéric Brin <duckx@mezimail.com>
blackduckx
force-pushed
the
fix/title-ampersand-anchor-macro
branch
from
August 4, 2026 14:39
ea5a5dd to
33819e2
Compare
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.
…ters
Section titles containing characters flagged as "unsafe" by ascii_quote() (e.g.
&) never received an<ac:structured-macro ac:name="anchor">in the generated storage-format output, even though the heading text itself rendered correctly.The anchor target for a title is registered in
_register_doctree_targets(builder.py) keyed on the section'sids(docutils' ascii-safe, punctuation-stripped slug), unconditionally. Butvisit_title(storage/translator.py) looked that target up using a different key, rebuilt from the section'snames(which keeps punctuation like&). For titles with no special characters both keys happened to match; for a title like "Foo & Bar" they diverged ("foo-bar" vs "foo-&-bar"), the lookup silently returned nothing, and the anchor macro was skipped entirely.The fix makes
visit_titlekey its lookup off the section'sidsdirectly, matching exactly what is registered, so the anchor is always found regardless of the title's characters.Adds a regression test (dataset + test case) covering a section title with an ampersand, including its local table-of-contents backlink.