danfickle / openhtmltopdf

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!

Home Page:https://danfickle.github.io/pdf-templates/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

:lang CSS selector support?

fungc opened this issue · comments

commented

Hi guys,
I am trying to produce a PDF, but my HTML has <style> with the :lang CSS selector.
https://www.w3schools.com/cssref/sel_lang.asp

And I have the html attribute like
https://www.w3schools.com/tags/att_global_lang.asp

However, the produced PDF is ignoring styles in body:lang(de) {}

Is there someway I can make this work? Thanks!

commented

Ok I think I might have found the bug

Suppose we have

attRes.getLang(e) with return "ja" for the html element, but return empty string "" for the body element.

This means getLang is not looking up the parent lang attribute.

Is that expected?

I finally found example 30 from Selectors Level 4 which suggest our behavior is wrong:

In this HTML example, only the BODY matches ''[lang|=fr]'' (because it has a LANG attribute) but both the BODY and the P match :lang(fr) (because both are in French). The P does not match the ''[lang|=fr]'' because it does not have a LANG attribute.

<body lang=fr>
  <p>Je suis français.</p>
</body>

I'll commit a fix that looks up the parent chain for a lang attribute. In the meantime, if you know the element the lang attribute is set on, you could of course use a descendant selector.

html:lang(ja) body { }
commented

From reading the source code I found that this works with the current version
<meta http-equiv="Content-Language" content="de" />
But yes it would be better to have a fix