fix: auto-fit PPTX table export to the slide - #238
Merged
Conversation
PptxGenJS in autoPage:false mode does no wrapping maths — it emits
<a:tr h="{h/rows}"> (a minimum PowerPoint grows to fit the text) with
equal-width columns, so a dense table ran off the slide and wrapped into
lopsided rows, unlike the live preview which zoom-scales it to fit.
Add fitTableToArea(): content-weighted column widths, an estimated
wrapped height, and a font-size step-down (14pt to a 7pt floor) until the
table fits its area, with explicit per-row heights handed to PowerPoint.
When even the minimum font can't fit, the rows are squeezed so the frame
still lands on the slide and a warning is surfaced. addTable now returns
the height consumed so the caption anchors under the fitted table.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Problem
A Markdown slide with body text and a 4-column, 7-row table renders fine in the
Kova preview but, when exported to PPTX, the table overruns the bottom of the
slide and its rows come out misshapen.
The preview keeps it in bounds because every body pane is an
OverflowPanethatmeasures the rendered height and zoom-scales the content to fit. The exporter has
no equivalent:
addTablehanded PptxGenJS a fixed area and a fixed 14pt fontwith
autoPage: false, in which mode PptxGenJS does no wrapping maths at all -it emits
<a:tr h="{h / rowCount}">and leaves layout to PowerPoint.a:tr/@his a minimum, so PowerPoint grows every row to fit its text and never shrinks
the font, and the columns are split equally regardless of content, so a
long-text column wraps into tall, uneven rows.
Change
New
fitTableToArea()helper, the export-time analogue ofOverflowPane:normalised, replacing PptxGenJS's equal split.
to a 7pt floor until the estimated table height fits its area.
renders close to what was computed rather than growing rows off the slide.
the slide and a warning is surfaced through the export's
warnings[].addTablenow returns the height it consumed so the caller anchors the tablecaption directly under the fitted table. Cell margins set to narrow,
valign: 'top'set explicitly.Observed on the reported case (body text plus a 4x7 table): shrinks to about
8pt, the description column gets roughly 5.1" and the owner column about 0.9",
total height about 1.8" - fits under the paragraph with no overflow.
Out of scope
The
textFracheuristic that decides how much of the body a table gets whenmixed with text is untouched; it is a little generous to the text, so a table
next to a short paragraph can end up smaller than necessary. Worth a follow-up.
Tests
exportPptxTableFit.test.ts: dense table fits within the slide and shrinksbelow 14pt; small table stays at 14pt with equal columns; wide-content column
gets more than twice the width of a short one; oversized table clamps at 7pt
and warns.
tscclean; full export suite and layout tests pass. Two pre-existing failuresin
src/engine/sheet/__tests__/evaluate.test.tsare unrelated (confirmed bystashing this change).
🤖 Generated with Claude Code