Skip to content

fix: prevent orphaned headings at page breaks#1

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

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
Copy Markdown

@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.
araa47 added a commit that referenced this pull request Mar 22, 2026
- Add CondPageBreak before headings to avoid orphans at page bottom
- Wrap heading + decorators in KeepTogether for atomic rendering
- Set keepWithNext=True on all heading styles
- Add structural and integration tests for orphan prevention
- Bump version to 0.2.0
- Add CHANGELOG.md
- Improve README with badges, features section, and better structure

Thanks to @0xlaveen for identifying the orphaned heading issue in #1.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@araa47
Copy link
Copy Markdown
Owner

araa47 commented Mar 22, 2026

Thanks for identifying this issue and putting together the fix, @0xlaveen! 🙏

We've incorporated your approach (CondPageBreak + KeepTogether + keepWithNext) in #2 along with tests and some other improvements. Closing this in favor of that PR — really appreciate the contribution!

@araa47 araa47 closed this Mar 22, 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.

2 participants