Skip to content

Fix TOC page numbers#8

Open
jdillard wants to merge 1 commit into
mainfrom
fix-toc
Open

Fix TOC page numbers#8
jdillard wants to merge 1 commit into
mainfrom
fix-toc

Conversation

@jdillard
Copy link
Copy Markdown
Owner

@jdillard jdillard commented May 27, 2026

Summary

Fix PDF TOC entries missing page numbers when building large multi-page singlehtml docs.

Problem

Fixes useblocks#120.

In singlehtml/simplepdf builds, section IDs collide after merging documents, so TOC target-counter links fail. Sphinx 8.2+ also strips docname-qualified refuri values via fix_refuris, leaving bare #introduction hrefs that do not match body anchors.

Approach

  • Prefix section refid / ids with docname in SimplePdfBuilder.assemble_doctree() using /{docname}/#{id} (same approach as [singlehtml] add docname to section anchor to make them unique sphinx-doc/sphinx#13739).
  • Align assemble_toc_secnumbers() / assemble_toc_fignumbers() and SimplepdfTranslator lookups.
  • Override fix_refuris() so qualified sidebar TOC links are preserved.
  • Override get_target_uri() to #/{docname}/ for document-level links.

Test plan

  • New test: duplicate section titles across two source files → unique IDs in HTML
  • New test: sidebar TOC section hrefs resolve to existing anchors
  • pytest green in CI (WeasyPrint available)
  • Manual: build demo project PDF and verify TOC page numbers

Related

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.

TOC Generation broken

1 participant