CSS leader in RTL direction causes boxes overflow
Author: Mi-LaCreated Oct 10, 2025Updated Aug 14, 2026
Labelsbug
Hello! I try to detect overflow in PDF automatically and I found out that in RTL mode the CSS leader causes overflow in some parent boxes.
Minimal reproducible example:
import weasyprint
HTML = """
<html>
<head>
<style type="text/css">
#toc ul li span::after {
content: leader(dotted);
}
#toc ul li span {
border: solid 1px black;
}
</style>
<body dir="rtl">
<div id="toc">
<ul>
<li>Section 1<span></span>1</li>
</ul>
</div>
</body>
</html>
"""
html = weasyprint.HTML(string=HTML)
doc = html.render()
# debug boxes:
# page = doc.pages[0]
# print(page.width, page.height)
# for box in page._page_box.descendants():
# print(box, box.position_x, box.position_y, box.width, box.height)
doc.write_pdf("test.pdf")Result:
When checking the debug printouts (commented out):
...
<BlockBox li> 83.0 134.583984375 587.7007874015749 21.7919921875
<Placeholder <BlockBox li::marker>> 670.7007874015749 134.583984375 9.9521484375 21.7919921875
<BlockBox li> 83.0 134.583984375 587.7007874015749 21.7919921875
<LineBox li> 587.2115295890749 134.583984375 587.7007874015749 21.7919921875
<TextBox li> 602.1558655265749 134.583984375 68.544921875 21.7919921875
<InlineBox span> 596.1558655265749 134.583984375 508.21152958907487 16
<InlineBox span::after> 597.1558655265749 134.583984375 508.21152958907487 16
<InlineBox span::after> 92.9443359375 134.583984375 508.21152958907487 16
<TextBox span::after> 594.7007874015749 134.583984375 4.0 21.7919921875
<TextBox span::after> 590.7007874015749 134.583984375 4.0 21.7919921875
...Note that <LineBox li> is first which overflows page width while <BlockBox li>' has correct dimensions.
I wonder why there are two <InlineBox span::after> and I suppose that the first one which overflows is the root cause of this issue.
Without using leader(dots) the boxes are correct - e.g. when using content: "........".
Hopefully this will be an easy fix :-).
Thank you for the amazing weasyprint!
Source: Kozea/WeasyPrint