Skip to content

fix(print): flex-fallback grids with a grid-heading for WeasyPrint#2

Open
ntheanh201 wants to merge 1 commit into
slidr-cli:masterfrom
ntheanh201:fix/print-grid-heading-weasyprint
Open

fix(print): flex-fallback grids with a grid-heading for WeasyPrint#2
ntheanh201 wants to merge 1 commit into
slidr-cli:masterfrom
ntheanh201:fix/print-grid-heading-weasyprint

Conversation

@ntheanh201

Copy link
Copy Markdown
Contributor

Problem

In PDF (WeasyPrint) output, any slide with a ::: grid that contains a ::: card {grid-heading} renders broken: the spanning heading (grid-column: 1 / -1) makes WeasyPrint mis-size the 1fr tracks, so the sibling metric/content cards collapse to ~0 width and text wraps one character per line. Browsers render the same markup correctly, so it only shows in the PDF.

This hits the metric/ecosystem layouts (e.g. a community-stats slide: grid {cols=5} with a grid-heading + metric cards).

Fix

In @media print only, fall back to flexbox for .grid:has(> .grid-heading): the grid-heading spans a full row (flex: 0 0 100%) and sibling cards share the next row equally. Grids without a grid-heading keep the CSS-grid path, and screen rendering is unchanged.

Test

Added a regression guard in tests/test_html.py asserting the print stylesheet contains the flex fallback. Verified by rendering an affected slide to PDF before/after (collapsed columns → proper metric cards).

WeasyPrint mis-sizes 1fr grid tracks when a full-width spanning
grid-heading (grid-column: 1 / -1) is present, collapsing sibling
cards to near-zero width — metric/ecosystem layouts render as narrow
columns with text wrapping one character per line in the PDF.

Fall back to flexbox for .grid:has(> .grid-heading) in @media print
only; grids without a grid-heading keep the CSS grid path, and screen
rendering is unchanged.

Signed-off-by: The Anh Nguyen <ntheanh201@gmail.com>
@ntheanh201
ntheanh201 force-pushed the fix/print-grid-heading-weasyprint branch from 622544f to 7f951f4 Compare July 24, 2026 02:08
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