Skip to content

Improve PDF content flow within chapters - #12

Closed
jinjoolee07 wants to merge 1 commit into
mainfrom
jin/improve-pdf-pagination
Closed

Improve PDF content flow within chapters#12
jinjoolee07 wants to merge 1 commit into
mainfrom
jin/improve-pdf-pagination

Conversation

@jinjoolee07

Copy link
Copy Markdown
Contributor

Closes #11

@sehkone

sehkone commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Reviewed this, and the direction is right — but it turns out the bug it fixes is bigger than the issue describes, and the patch as written introduces one visible regression. I put the rebased branch and the follow-up in #35, which keeps your commit as-is and adds the corrections on top.

The forced break was dropping content, not just padding pages. When a nav section groups several pages, mkdocs-with-pdf emits one article of stacked section elements, and page-break-before: always on section + section silently drops everything after each section's first paragraph. Against a nav-grouped fixture, main renders 5 pages with a 22-row table, a 14-item list, an admonition and an 18-row table all missing; with your break-before: auto they come back and it renders 9. Splitting the rules apart, min-height: auto alone changes nothing — page-break-before: always is the whole cause. So the first of your three blocks is the fix, and it is worth more than the issue asked for.

Neither sample exercises that path, which is why nobody saw it: both are a single page, so the plugin reports Converting 1 articles and no section is ever created.

div.admonition { break-inside: auto } breaks the box. Building samples/manual on this branch versus main, pages 5–6 differ: the Tip admonition now splits at the page boundary and renders as an open box — title bar plus an empty half-box at the foot of page 5, body with no left or right border on page 6. Page count is unchanged at 8, so it traded a clean break for a broken box and saved nothing. Same risk for div.tabbed-content--wrap, which is also a bordered container.

Relaxing break-before is what strands the short labels. The plugin's page-break-before: avoid on ul/ol/table is what keeps a block attached to the sentence or bold-only label above it. Clearing it left **Key inputs** at the foot of a page with one list item — which is the "short labels appearing almost alone on a page" symptom from #11. Relaxing break-inside only, and leaving break-before alone, fixes that without giving up any of the compaction.

Two smaller things:

  • styles/pdf.css in both templates still ships table, pre, blockquote, ul, ol { break-inside: avoid }. It is loaded into the PDF render too (I confirmed by putting p { color: red } in it and watching the PDF text turn red), so the theme was shipping one file forbidding what another forces with !important, and browser print and PDF export broke pages differently.
  • The !importants are not needed. Nothing they compete with is !important, and article:not(#doc-cover):not(#doc-toc) … already outspecifies both the plugin's _paging.scss and styles/pdf.css.

Also worth knowing before you rebase: main has moved 10 commits, and the CHANGELOG hunk auto-merges without a conflict into something wrong — a second ## [Unreleased] below the real ## Unreleased, under the ### Changed heading the file no longer uses, plus an [Unreleased]: link it deliberately omits. And MD013: false was dropped, so the one-line entry at 137 characters now fails Lint Markdown.

Happy to close this in favour of the other PR, or to push the corrections here instead if you'd rather keep this branch — your call.

@sehkone

sehkone commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Closing in favour of #35, which carries this commit rebased onto main with the review follow-up and a regression test. Thanks — the section + section relaxation in here is what turned out to fix the content loss, and it is credited as co-author on the squashed commit.

@sehkone sehkone closed this Aug 8, 2026
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.

Improve within-chapter PDF pagination

2 participants