#2308·WeasyPrint

white-space: pre-wrap wraps spans prematurely

Author: nnseeCreated Nov 22, 2024Updated Aug 27, 2026
Labelsbug

Hi there! Spans seem to be wrapped to a new line in their entirety when white-space: pre-wrap is set.

Repro code:

xml
<style>
.highlight {
  background-color: #ffff00;
}
code {
  white-space: pre-wrap;
  display: block;
  max-width: 250px;
}
</style>
<code>
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
</code>
<hr>
<code>
00 00 00 00 00 00 00 00 00 00 <span class="highlight">00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</span> 00 00 00 00 00
</code>

WeasyPrint output:

Image

Expected output:

Image

Not quite sure why this is happening or how to stop it from happening.