Skip to content

fix(make-pdf): hide empty TOC page numbers and dot leaders in print - #2467

Open
dylansacks62 wants to merge 1 commit into
garrytan:mainfrom
dylansacks62:fix/toc-hide-empty-page-numbers
Open

fix(make-pdf): hide empty TOC page numbers and dot leaders in print#2467
dylansacks62 wants to merge 1 commit into
garrytan:mainfrom
dylansacks62:fix/toc-hide-empty-page-numbers

Conversation

@dylansacks62

Copy link
Copy Markdown

Problem

make-pdf generate --toc produces a table of contents where dot leaders run from each entry title into blank space. It reads as a broken document.

Cause: .toc-page is filled by a CSS target-counter, which only resolves under Paged.js. Paged.js is not vendored in gstack, and Chrome has no native target-counter, so the spans stay permanently empty while the leader dots still render. browse/src/meta-commands.ts:545 already documents the constraint: "make-pdf v1 ships without Paged.js; TOC renders without page numbers."

This is not fixable in CSS alone as long as the counter has nothing to resolve against.

Fix

Hide .toc-dots and .toc-page in print until page numbers actually exist. screenCss() already does exactly this for HTML output, so this brings print in line with the path that was already correct. A comment marks the two rules to restore the day Paged.js lands.

Also: buildTocBlock mapped every heading at H2 or deeper to level-2, so H3 sub-sections sat at the same indent as numbered sections and read as top-level peers. H3 now gets its own level-3 class.

Result

Clean, clickable, correctly nested TOC. No trailing dots. Cover page, running headers, N of M footers unaffected.

Testing

  • bun test in make-pdf/: 189 pass, 0 fail, 393 expect() calls across 11 files.
  • Verified visually on a 9-page letter-format document with a cover page: rasterized the output and confirmed zero leader-dot glyphs in the TOC region, correct H2/H3 nesting, and intact headers and footers.

Note

If Paged.js is ever vendored, revert the single display: none rule and the original two declarations are restored verbatim from the comment. The level-3 change is independent and should stay either way.

🤖 Generated with Claude Code

Paged.js is not vendored in gstack, so the `target-counter` that would
fill `.toc-page` never resolves (browse/src/meta-commands.ts:545 documents
this: "make-pdf v1 ships without Paged.js; TOC renders without page
numbers"). Chrome has no native target-counter, so the spans stay empty
and the dot leaders run from each title into blank space, which reads as
a broken document.

screenCss() already hides both for HTML output. Do the same for print
until page numbers actually exist, and leave a comment to restore the
two rules if Paged.js ever lands.

Also give H3 its own `level-3` class. buildTocBlock mapped every heading
>= H2 to `level-2`, so sub-sections sat at the same indent as numbered
sections and read as top-level peers.

189/189 make-pdf tests pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Aug 6, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

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