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

Find a way to easily reach the internal values of the rendered tree #434

Closed
G-E-N-E opened this issue Feb 21, 2017 · 4 comments
Closed

Find a way to easily reach the internal values of the rendered tree #434

G-E-N-E opened this issue Feb 21, 2017 · 4 comments
Labels
feature New feature that should be supported

Comments

@G-E-N-E
Copy link

G-E-N-E commented Feb 21, 2017

I'm not sure if this is a bug or intended behavior but the height of a box is 'auto' after rendering unlike the width of the box which appears to be being calculated based on the content.

How can I get the calculated height of the element id=header from the rendered document, i.e.
doc = HTML(string=html_below).render(stylesheet=[CSS(css_below)])?

It seems like the width of the elements is calculated but the height remains set to 'auto'.
I'd like to resolve this to a unit so unfixed elements (not shown) can be positions relative to the dynamic height.

HTML

<div id="header">
  <div id="header-right">
    <div>Row 1, Column 2</div>
    <div>Row 2, Column 2</div>
  </div>

  <div>
    <div>Row 1, Column 1</div>
    <div>Row 2, Column 1</div>
  </div>
</div>

CSS

#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}

#header-right {
  float: right;
  text-align: right;
}
@liZe
Copy link
Member

liZe commented Feb 23, 2017

There's no "official" and reliable way to get the boxes and their attributes. But with the current version, you can try to get what you want:

>>> doc.pages[0]._page_box.children[0].children[0].children[0]
<Placeholder <BlockBox div None>>
>>> doc.pages[0]._page_box.children[0].children[0].children[0].style['position']
'fixed'
>>> doc.pages[0]._page_box.children[0].children[0].children[0].height
37.28125

AFAIK, there's currently no easy way to automatically get what you want (for example, get the blocks corresponding to your tags using their id), but it may be possible to override some classes and functions if you really need it.

@G-E-N-E
Copy link
Author

G-E-N-E commented Feb 23, 2017

This is the same conclusion I've come too.
I'm in the progress of defining some access functions around id's and element types; I'll post what I come up with in case anyone is interested.

@liZe
Copy link
Member

liZe commented Feb 23, 2017

I'm in the progress of defining some access functions around id's and element types; I'll post what I come up with in case anyone is interested.

Cool!

@liZe liZe added the feature New feature that should be supported label Feb 23, 2017
@liZe liZe changed the title Box auto height value not calculated to px Find a way to easily reach the internal values of the rendered tree Feb 23, 2017
Tontyna added a commit to Tontyna/WeasyPrint that referenced this issue Oct 17, 2019
Unless the Box is a PageBox or a MarginBox the new attribute `element` points
to the html element (xml.etree.ElementTree.Element) where the Box stems from.
This enables e.g. post-processing that depends on Element attributes, like
'class' or 'id'.

Caution: Elements with no subelements will test as False! Test the element's
existence with `if box.element is not None:`.

Related to Kozea#434, Kozea#970.
@liZe
Copy link
Member

liZe commented Dec 27, 2019

I think that 4365b19 gives a nice way to enable post-processing operations. Feel free to reopen if needed!

@liZe liZe closed this as completed Dec 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature that should be supported
Projects
None yet
Development

No branches or pull requests

2 participants