Add line-level pagination with widow/orphan control#120
Open
Conversation
…ntrol (Issue #30) Paragraphs exceeding page height are now split at line boundaries using Range API measurement instead of overflowing. Widow/orphan control ensures configurable minimum lines at page top/bottom (default 2). Respects Word's w:widowControl and w:keepLines properties via existing data attributes. https://claude.ai/code/session_01PzsJ5ZDVcFnZ2tTo28bDBa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements line-level paragraph splitting during pagination to prevent widows and orphans, addressing Issue #30. Paragraphs that exceed page height are now intelligently split at line boundaries rather than overflowing, with configurable minimum line constraints at page boundaries.
Key Changes
measureLines()method using the Range API andgetClientRects()to precisely detect line boundaries within paragraph elementssplitParagraphAtLine()to split paragraphs at specific line boundaries using CSS clipping and margin adjustmentstrySplitWithWidowOrphan()to enforce minimum line counts:minOrphanLines(default: 2): minimum lines kept at bottom of pageminWidowLines(default: 2): minimum lines moved to top of next pageflowSplitRemainder()andsplitBlockAcrossPages()to handle remainders that span multiple pagesPaginationOptionswithminOrphanLinesandminWidowLinesparameterswidowControlproperty toMeasuredBlockinterface, parsed fromdata-widow-controlattribute (defaults to true per Word behavior)keepLinespropertyImplementation Details
w:keepLinesparagraph property to prevent splitting when specifiedhttps://claude.ai/code/session_01PzsJ5ZDVcFnZ2tTo28bDBa