Skip to content

fix(links): match Asciidoctor's ids for anchored sections and listings - #1

Merged
darwin67 merged 1 commit into
mainfrom
fix-section-anchors
Oct 21, 2026
Merged

darwin67 merged 1 commit into
mainfrom
fix-section-anchors

Conversation

@darwin67

Copy link
Copy Markdown
Member

rfdtool check validates links to sections (<<goal>>, link:../0005/README.adoc#goal[...]) against the ids it expects Asciidoctor to generate. It accepted ids that don't exist, so a broken section link could pass.

What changes

  • Explicit anchors replace the title id. A section with [[values]] (or [#id], [id=...]) above it, or [[id]] in its title, gets only that id, as in Asciidoctor. Block attributes apply across blank lines.
  • Anchors in literal blocks are text. [[exporters]] in a TOML listing no longer counts as an anchor. Listings, literals and passthroughs that set subs= are still scanned, since they can render anchors; comment blocks never are.
  • Shorthand ids after a style ([source#id], [discrete#id.role]) are now accepted; they were missed before.

Where it can't tell, the checker keeps the id: a false accept only misses a broken link, but a false reject blocks a valid one. The only known false accept is an anchor-looking quoted value such as [role="[[x]]"].

Verification

Compared with asciidoctor.js 4.1.1 using the RFD site's settings (idprefix="", idseparator="-"), on the 24 Renga RFDs plus 30 edge-case snippets:

ids Asciidoctor doesn't generate ids it generates but rfdtool rejects
main 20 3
this PR 1 (the case above) 0

The new TestSectionIDs cases fail on main. go test ./..., golangci-lint and rfdtool check on the Renga RFDs (including RFD_BASE_REF=origin/main) pass.

Found while evaluating Go AsciiDoc parsers: kilabit.info/asciidoctor-go exposes no document tree, misreads titles after header attributes, and generates different ids for titles with punctuation, so it isn't adopted here.

sectionIDs accepted ids that Asciidoctor never generates, so a link to a
missing section could pass rfdtool check:

- A section whose block attributes or title set an id, as with [[values]]
  above it, gets that id instead of one from its title. sectionIDs added
  both. Block attributes apply across blank lines, as in Asciidoctor.
- [[exporters]] in a TOML listing is text, not an anchor. sectionIDs read
  anchors in literal blocks, which it already skipped for section titles.

It also missed an id shorthand after a style, as in [source#id] or
[discrete#id], which it now accepts.

Where it cannot tell, sectionIDs keeps an id rather than rejecting a
valid link: listings that set subs= may render anchors, an anchor inside
monospace text still renders, and a quoted attribute value that looks
like an anchor does not take the section's title id away.

Against asciidoctor.js 4.1.1 with the site settings, across the 24 Renga
RFDs and 30 edge cases, main accepted 20 ids that do not exist and missed
3; this accepts 1 that does not exist, deliberately, and misses none.

Amp-Thread-ID: https://ampcode.com/threads/T-01a15d15-bb12-7429-9794-374e145cd95e
Co-authored-by: Amp <amp@ampcode.com>
@darwin67
darwin67 merged commit 4f41279 into main Oct 21, 2026
3 checks passed
@darwin67
darwin67 deleted the fix-section-anchors branch October 21, 2026 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant