Skip to content
New issue

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

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

Already on GitHub? # to your account

Avoid line break between html elements and text #39

Open
i4i4n opened this issue Sep 30, 2016 · 7 comments
Open

Avoid line break between html elements and text #39

i4i4n opened this issue Sep 30, 2016 · 7 comments
Assignees

Comments

@i4i4n
Copy link

i4i4n commented Sep 30, 2016

Considering the following example:

<!DOCTYPE html>
<html>
<meta charset="utf8" />
<head>
</head>
<body>
some long text… (<span class="keyword">example</span>) …some long text… «&nbsp;<span class="keyword">example2</span>&nbsp;» some long text… <i>example3</i>.
</body>
</html>

Firefox, Safari, Chrome will never break between the texts in spans and the (immediate-)surrounding characters.

But, depending on the position of the text, openhtmltopdf may put a line break between:

  • "(" and "example" or "example" and ")"
  • same between "«"/"»" and "example2"
  • same between example3 and "."

This results in not properly formatted text.
The texts here in the spans should be considered as being on the same level as the surrounding text.

More generally, this should probably be the default behavior for any inline tags.

@danfickle
Copy link
Owner

@i4ntch1k - Sorry for leaving this for so long. I can confirm this is a bug. It shouldn't break at the boundaries of inline elements (unless there is a legitimate breaking opportunity).

I'll investigate shortly. Thanks again.

@MichelSlice
Copy link

Hi, is there a workaround for this?

@danfickle
Copy link
Owner

Hi @MichelSlice

Sorry, no fix. I thought it would be rare that someone wants to markup a partial word. Could you give a hint of your use case?

@MichelSlice
Copy link

MichelSlice commented Feb 13, 2018 via email

@aRusenov
Copy link

aRusenov commented Jun 1, 2018

I can confirm it's still an issue on the latest version 0.0.13-RC. Our use case is for example:

The products that are listed for sale on the Platform ("
<strong>Items</strong>")

Can also confirm it's because strong is inline. Without any inlines in the way the wrapping is correct.

@danfickle
Copy link
Owner

danfickle commented Jun 8, 2018

Hi @aRusenov

The problem is that the applicable code is in a 300 line critical method with no tests! It's a bit of a mess. Have a look:

public static void layoutContent(LayoutContext c, BlockBox box, int initialY, int breakAtLine) {

@danielblazquez
Copy link

danielblazquez commented Nov 14, 2018

My workaround for commas and points after an inline element (strong, em..): place any problematic symbol inside the inline tag.

Regexp
<\/(strong|em)>([,.:])
$2</$1>

@danfickle danfickle self-assigned this Jan 3, 2021
burka pushed a commit to burka/openhtmltopdf that referenced this issue May 3, 2024
* Add version 1.1.5 to 1.1.8 to README changelog and refer to commit log for newer releases

Signed-off-by: XSpielinbox <55600187+xspielinbox@users.noreply.github.com>

* Fix changelog according to corrected 1.1.4 tag

Signed-off-by: XSpielinbox <55600187+xspielinbox@users.noreply.github.com>

---------

Signed-off-by: XSpielinbox <55600187+xspielinbox@users.noreply.github.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants