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

white-space: nowrap still wraps on hyphens #189

Smylers opened this issue May 1, 2014 · 7 comments

white-space: nowrap still wraps on hyphens #189

Smylers opened this issue May 1, 2014 · 7 comments


Copy link

@Smylers Smylers commented May 1, 2014

With white-space: nowrap, WeasyPrint will still wrap text on a hyphen (technically U+2D hyphen-minus) even when it won't wrap on a space at that point.

See:, which WeasyPrint (version 0.21) renders as:

Obviously hyphens aren't white space, but it doesn't seem helpful to wrap at this point. Unfortunately the stable CSS2.1 spec makes no mention of what the white-space property should do with wrapping characters that aren't white space:

However the CSS3 editors' draft makes clear that white-space governs all ‘soft wrap opportunities’, which includes punctuation characters where wrapping can occur:

Copy link

@SimonSapin SimonSapin commented May 2, 2014

I believe this is Pango’s doing. IMO the "proper" fix for this and other related bugs would be to do line breaking ourselves in WeasyPrint rather than leave it to Pango. But for this specifically maybe we can special-case white-space: nowrap and give infinite available width to Pango, rather than just replace spaces with no-break spaces as (IIRC) we do now.

Copy link
Contributor Author

@Smylers Smylers commented Mar 3, 2015

rather than just replace spaces with no-break spaces as (IIRC) we do now.

In that case, another possible way of getting this working would be to additionally massage the input text to Pango by inserting U+2060 word joiners just before and after each hyphen or slash character.

That is actually what I'm now doing in the HTML template for affected text, though obviously that's a layering violation, since it means that the HTML has to know which CSS rules will be applied where.

Copy link

@SirNeuman SirNeuman commented Apr 28, 2015

So is there any simple workaround for this problem currently? In my css i have white-space: nowrap, which works for spaces but not for hyphens.

Copy link
Contributor Author

@Smylers Smylers commented Apr 28, 2015

So is there any simple workaround for this problem currently?

Its simplicity is subjective, but the workaround I mention above is to process text that's going to be put in nowrap containers with:

$text =~ s!([/-])!\N{WORD JOINER}$1\N{WORD JOINER}!g;

I happen to be using Perl, but the underlying idea should translate straightforwardly to other text-processing languages.

Copy link

@SirNeuman SirNeuman commented Apr 28, 2015

Ahh ok. Sorry, by simple i meant either html or css way of doing it. I'll have to find the python equivalent of this then. I'm not too good with regex stuff, but it's always satisfying figuring it out.

Copy link

@liZe liZe commented Mar 8, 2016

Grouped in #301.

@liZe liZe closed this Mar 8, 2016
liZe added a commit that referenced this issue May 8, 2016
Copy link

@liZe liZe commented May 8, 2016

Even without rewriting the line breaking algorithm, this bug is fixed in a quite clean way.

jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Jan 15, 2017
Version 0.34

Released on 2016-12-21.

Bug fixes:

* `#398 <>`_:
  Honor the presentational_hints option for PDFs.
* `#399 <>`_:
  Avoid CairoSVG-2.0.0rc* on Python 2.
* `#396 <>`_:
  Correctly close files open by mkstemp.
* `#403 <>`_:
  Cast the number of columns into int.
* Fix multi-page multi-columns and add related tests.

Version 0.33

Released on 2016-11-28.

New features:

* `#393 <>`_:
  Add tests on MacOS.
* `#370 <>`_:
  Enable @font-face on MacOS.

Bug fixes:

* `#389 <>`_:
  Always update resume_at when splitting lines.
* `#394 <>`_:
  Don't build universal wheels.
* `#388 <>`_:
  Fix logic when finishing block formatting context.

Version 0.32

Released on 2016-11-17.

New features:

* `#28 <>`_:
  Support @font-face on Linux.
* Support CSS fonts level 3 almost entirely, including OpenType features.
* `#253 <>`_:
  Support presentational hints (optional).
* Support break-after, break-before and break-inside for pages and columns.
* `#384 <>`_:
  Major performance boost.

Bux fixes:

* `#368 <>`_:
  Respect white-space for shrink-to-fit.
* `#382 <>`_:
  Fix the preferred width for column groups.
* Handle relative boxes in column-layout boxes.


* Add more and more documentation about Windows installation.
* `#355 <>`_:
  Add fonts requirements for tests.

Version 0.31

Released on 2016-08-28.

New features:

* `#124 <>`_:
  Add MIME sniffing for images.
* `#60 <>`_:
  CSS Multi-column Layout.
* `#197 <>`_:
  Add hyphens at line breaks activated by a soft hyphen.

Bux fixes:

* `#132 <>`_:
  Fix Python 3 compatibility on Windows.


* `#329 <>`_:
  Add documentation about installation on Windows.

Version 0.30

Released on 2016-07-18.

WeasyPrint now depends on html5lib-0.999999999.

Bux fixes:

* Fix Acid2
* `#325 <>`_:
  Cutting lines is broken in page margin boxes.
* `#334 <>`_:
  Newest html5lib 0.999999999 breaks rendering.

Version 0.29

Released on 2016-06-17.

Bug fixes:

* `#263 <>`_:
  Don't crash with floats with percents in positions.
* `#323 <>`_:
  Fix CairoSVG 2.0 pre-release dependency in Python 2.x.

Version 0.28

Released on 2016-05-16.

Bug fixes:

* `#189 <>`_:
  ``white-space: nowrap`` still wraps on hyphens
* `#305 <>`_:
  Fix crashes on some tables
* Don't crash when transform matrix isn't invertible
* Don't crash when rendering ratio-only SVG images
* Fix margins and borders on some tables

Version 0.27

Released on 2016-04-08.

New features:

* `#295 <>`_:
  Support the 'rem' unit.
* `#299 <>`_:
  Enhance the support of SVG images.

Bug fixes:

* `#307 <>`_:
  Fix the layout of cells larger than their tables.


* The website is now on GitHub Pages, the documentation is on Read the Docs.
* `#297 <>`_:
  Rewrite the CSS chapter of the documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants