Skip to content

Support basic display: contents#2746

Open
moreaki wants to merge 1 commit into
Kozea:mainfrom
moreaki:fix-display-contents
Open

Support basic display: contents#2746
moreaki wants to merge 1 commit into
Kozea:mainfrom
moreaki:fix-display-contents

Conversation

@moreaki
Copy link
Copy Markdown
Contributor

@moreaki moreaki commented Apr 22, 2026

Fixes #2210.

Context

#2210 reports that tabbed content generated by Material for MkDocs / PyMdown Extensions is rendered in the wrong order when wrappers use display: contents inside a flex container. WeasyPrint currently rejects display: contents during CSS validation, so these wrappers generate real boxes instead of being flattened into their children.

The issue thread also mentioned that the same order problem could be reproduced without display: contents when inline label elements are direct flex children. On current main, that direct-inline case is already handled correctly by the existing flex item/blockification work related to #1652. The remaining missing part is the actual display: contents wrapper behavior.

Changes

  • Accept display: contents as a valid display value.
  • Compute display: contents on the root element back to a normal block-flow root box, avoiding a missing root box.
  • Flatten normal display: contents elements by returning their child boxes instead of a principal box.
  • Handle pseudo-element and marker edge cases so the new display value does not fall through to box creation paths that have no contents box type.
  • Add a regression test for the Support "display: contents" #2210 flex/tabbed-content structure, checking that the children are flex items in the expected order: Tab 1, Content Block 1, Tab 2, Content Block 2.

Scope and limitations

This is intended as a first, narrow implementation of display: contents. It fixes the concrete wrapper/flex case from #2210 and keeps the change small enough to review.

It does not claim complete CSS Display conformance. In particular, this does not deeply address every possible interaction of display: contents with accessibility/tree semantics, unusual pseudo-element behavior, replaced elements, or every layout model. The goal is to provide a useful first fix and let maintainers decide whether this approach is acceptable as a base for broader support.

Tests

  • venv/bin/python -m pytest tests/layout/test_flex.py tests/css/test_validation.py
  • venv/bin/python -m pytest tests/layout
  • venv/bin/python -m ruff check weasyprint/css/validation/properties.py weasyprint/css/computed_values.py weasyprint/formatting_structure/build.py tests/layout/test_flex.py
  • git diff --check

@moreaki moreaki marked this pull request as ready for review April 22, 2026 10: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.

Support "display: contents"

1 participant