fix(pdf): fix page breaks and element scaling for PDF export (fixes #166)#168
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Deploying markdown-viewer with
|
| Latest commit: |
70915f6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3fc26e46.markdown-viewer.pages.dev |
| Branch Preview URL: | https://codex-fix-pdf-page-breaks-16.markdown-viewer.pages.dev |
Deploying markdownviewer with
|
| Latest commit: |
70915f6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cb2bfc07.markdownviewer.pages.dev |
| Branch Preview URL: | https://codex-fix-pdf-page-breaks-16.markdownviewer.pages.dev |
…SVGs/images and resetting transient styles in cascade
…al scaling and gap-less page breaks
…ical font-size scaling for pre/math blocks
…g keep-with-next threshold check
…itioning, and parent block redirection for inline images
…ia safety buffer and valid list item shifting
beebb1b to
70915f6
Compare
9695ebd to
70915f6
Compare
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.
Description
This PR resolves the issue where text, lists, table rows, and MathJax formulas are cut or sliced horizontally in half across A4 page boundaries during PDF export (Fixes #166).
Key Improvements
1. Expanded Page-Break Detection
identifyGraphicElementsto include page-break sensitive text elements (p,li,blockquote,h1-h6,hr) and MathJax display containers (mjx-container[display="true"],.math-block). These are labeled as'text'or'math'to prevent boundary slicing.2. Dynamic Shift Offset Tracking
accumulatedShifttracking parameter insideinsertPageBreaks. As element margins are shifted down to begin at a new page boundary, subsequent element positions are dynamically offset to prevent coordinate overlap calculations from using stale values.3. Table Splitting & Header Replication
splitTablesandmergeSplitTableswhich divide tables exceeding a page's height into separate parts.theadheaders on subsequent pages for continuous reading.4. Cascade Stabilization
handleOversizedElementsinside the mainapplyPageBreaksWithCascadestabilization loop. Margins and scales are now resolved iteratively to guarantee layout stability.5. Height Slicing & Box Sizing Fixes
tempElement.scrollHeightwithMath.ceil(tempElement.getBoundingClientRect().height)in html2canvas window properties to handle transformed dimension heights correctly, eliminating empty trailing pages.fitExportElementToContentandfitMarkdownExportToContent./^\s*---/) so that newlines/whitespace preceding frontmatter do not break parsing.Verification Results
Verified the changes locally using Playwright:
jspdfandhtml2canvas) dynamically.