WeasyPrint icon indicating copy to clipboard operation
WeasyPrint copied to clipboard

Support "display: contents"

Open nbanyan opened this issue 1 year ago • 5 comments

I'm using Material for MkDocs with PyMdown Extensions and mkdocs-with-pdf. PyMdown has a tabbed content feature. This is a simplified example of the structure of the tabbed content with minimal CSS for print.

<div style="display: flex; flex-flow: column wrap">
  <div style="display:contents">
    <label style="order: 1;">Tab 1</label>
    <label style="order: 2;">Tab 2</label>
  </div>
  <div style="display: contents">
    <div style="order: 1; display block; ">
    Content Block 1
    </div>
    <div style="order: 2; display block; ">
    Content Block 2
    </div>
  </div>
</div>

In the browser this is displayed as:

Tab 1 Content Block 1 Tab 2 Content Block 2

Weasyprint renders this as:

Tab 1 Tab 2 Content Block 1 Content Block 2

Even placing all the 'order' elements directly under the 'display: flex' element gives the same result.

I proposed a workaround to PyMdown, but this should be resolved here.

nbanyan avatar Jul 25 '24 18:07 nbanyan

Hi!

Thanks for this bug report. That’s actually because display: contents is not supported. I change the title accordingly.

liZe avatar Jul 25 '24 22:07 liZe

It likely contributes, but the issue is still there without those elements. I included them because it is a potential complication to consider that is present in the tabbed extension's design.

<div style="display: flex; flex-flow: column wrap">
  <label style="order: 1;">Tab 1</label>
  <label style="order: 2;">Tab 2</label>
  <div style="order: 1; display block; ">
  Content Block 1
  </div>
  <div style="order: 2; display block; ">
  Content Block 2
  </div>
</div>

nbanyan avatar Jul 26 '24 01:07 nbanyan

That’s another problem caused by the fact that label elements are by default inline elements, and they’re wrapped inside anonymous block elements (instead of being flex items, as they should be). Adding display: block to labels gives the correct order. It’s probably related to #1652.

You can open a separate issue if you want to track it separately.

(And as you can see in other issues, flex layout should be rewritten.)

liZe avatar Jul 26 '24 06:07 liZe

Is there any estimate on when display: contents may be supported?

documentat-alibaev avatar Oct 28 '24 04:10 documentat-alibaev

Is there any estimate on when display: contents may be supported?

No, it’s not on our roadmap yet.

liZe avatar Oct 28 '24 08:10 liZe