WeasyPrint
WeasyPrint copied to clipboard
Add support for CSS property: word-break
Currently, word-break
is not supported, it's needed if you want to do fine-grained text layout, especially for CJK text.
Hello!
Strange, word-break
is documented as supported, but it’s definitely not. It should be possible to add the feature with the possibilities given by Pango.
It seems as though this is a particularly acute problem in tables, as it can't be worked around with overflow-wrap
in tables the way it can be in body text:
<style>
html {
overflow-wrap: break-word;
}
</style>
<table><tr><td>LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG</td></tr></table>
<p>LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG</p>
I suspect this is probably about to cause some issues for my uses. If you have a few minutes, can you point me towards where in the code I might try to poke to get either overflow-wrap
to work in tables or word-break
to work generally?
(edit: ignore the space before the last G
in the screenshot - that was a mistake on my part)
Hi, have you any plans about this feature?
It seems as though this is a particularly acute problem in tables
That’s right, it would be really useful.
Hi, have you any plans about this feature?
We have plans to rewrite the text management in the future, mostly to handle right-to-left and bidirectional text. But there’s nothing about that in the milestones yet.
If you have a few minutes, can you point me towards where in the code I might try to poke to get either
overflow-wrap
to work in tables orword-break
to work generally?
As far as I can remember, overflow-wrap
should work but we had some problems with Pango’s wrap mode that wasn’t working as expected. You can look at this code, that’s supposed to break lines at characters boundaries when needed:
https://github.com/Kozea/WeasyPrint/blob/22efdc832bde351dd68831954efb8e750864622f/weasyprint/text/line_break.py#L539-L556
Is this still an issue? I tested overflow-wrap: break-word
on a couple documents I have where some long URLs would overflow in a column layout, and it worked quite well.
Is this still an issue? I tested
overflow-wrap: break-word
on a couple documents I have where some long URLs would overflow in a column layout, and it worked quite well.
You’re right, it’s supported now. And if it works "quite well" in columns, we can assume that it works well enough everywhere else 😄.
Thanks a lot!