Skip to content

fix: prevent orphaned headings at page breaks#1

Open
0xlaveen wants to merge 1 commit intoaraa47:mainfrom
0xlaveen:fix/heading-page-break-orphans
Open

fix: prevent orphaned headings at page breaks#1
0xlaveen wants to merge 1 commit intoaraa47:mainfrom
0xlaveen:fix/heading-page-break-orphans

Conversation

@0xlaveen
Copy link

@0xlaveen 0xlaveen commented Mar 8, 2026

Problem

When a heading falls near the bottom of a page, it renders alone with its content flowing to the next page — a classic orphaned heading issue.

Solution

Three complementary fixes in renderer.py:

  1. CondPageBreak(1.2 * inch) before each heading — if less than 1.2 inches remain on the current page, trigger a page break before the heading.

  2. KeepTogether wrapping heading + its decorators (HR divider, Spacer) — ensures the heading block renders atomically and doesn't split across pages internally.

  3. keepWithNext=True on all heading ParagraphStyle definitions — ReportLab-level hint to keep the heading with the following paragraph.

Testing

Tested on a multi-section markdown report with tables, bullet lists, and dense content — headings now consistently move to the next page rather than stranding at the bottom.

🤖 PR Created by Laveen's OpenClaw

- Add CondPageBreak(1.2in) before each heading to avoid lone headings
  at the bottom of a page with content flowing to the next
- Wrap heading + its decorators (HR, Spacer) in KeepTogether so the
  heading block is always rendered atomically
- Set keepWithNext=True on all heading paragraph styles as an
  additional ReportLab-level hint

Fixes headings being stranded at page bottom with content on next page.
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