Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline-block ignores its padding/border/margin when calculating its max width #1235

Closed
mtkennerly opened this issue Oct 13, 2020 · 4 comments
Labels
bug Existing features not working as expected
Milestone

Comments

@mtkennerly
Copy link

This is a follow-up from #1234. Context:

Using the latest WeasyPrint master code, the PDF does wrap long lines in code blocks, but each line is cut off prematurely, and there are some extra blank lines after the last wrapped line.

Documents produced by above Github workflow: samples2.zip

HTML:

image

PDF:

image

@mtkennerly
Copy link
Author

mtkennerly commented Oct 14, 2020

As a workaround, I tried adding this to the Markdown:

<style type="text/css" scoped>
.sourceCode {
    white-space: pre-wrap !important;
}
</style>

Documents: samples3-inline-css.zip

In the HTML version, that gives me what I want:

image

However, the PDF is unchanged. It seems like the white-space rule is ignored:

image

@liZe liZe added the bug Existing features not working as expected label Oct 21, 2020
@liZe
Copy link
Member

liZe commented Dec 10, 2020

Hello!

This problem is fun 😄.

Lines are split, but it’s not a bug, it’s a feature. The stylesheet from your document has this rule, that only applies for print:

  @media print {
    pre > code.sourceCode { white-space: pre-wrap; }
    pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em }
  }

The white-space: pre-wrap rule makes lines break, and it’s actually quite clever for print, because you won’t be able to scroll.

The second rule, text-indent: -5em; padding-left: 5em is a little bit more cryptic, but it’s actually a nice workaround: it makes normal lines be displayed normally (-5em, +5em) and makes cut lines displayed with a 5em indentation (indent only applies to the first line of a block). The normal result is pretty nice (from a browser with print rules forced enabled):

Capture d’écran de 2020-12-10 21-32-05

We have a bug in WeasyPrint. The spans, displayed as inline blocks, have a content width of 100%, ignoring their left padding (that should set their size to 100% - 5em instead, to have a padding-box width of 100%). So, the text is 5em too wide, making it disappear on the right.

I’ll try to create a very small example showing the problem.

@liZe liZe changed the title Long lines in PDF code blocks are wrapped, but also cut off Inline-block ignore its padding when calculating its max width Dec 10, 2020
@liZe liZe changed the title Inline-block ignore its padding when calculating its max width Inline-block ignores its padding when calculating its max width Dec 10, 2020
@liZe liZe changed the title Inline-block ignores its padding when calculating its max width Inline-block ignores its padding/border/margin when calculating its max width Dec 10, 2020
@liZe
Copy link
Member

liZe commented Dec 10, 2020

<span style="background: red; display: inline-block; margin: 0 100px">a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h a b c d e f g h </span>

@liZe liZe closed this as completed in 626177b Dec 14, 2020
@liZe
Copy link
Member

liZe commented Dec 14, 2020

The result is really nice 😍! Very interesting way to display pre tags for print, thanks a lot for reporting this issue.

Capture d’écran de 2020-12-14 07-16-15

@liZe liZe added this to the 53.0 milestone Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants