You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HTML line breaks incorrectly preserved in Markdown output #2922
HTML line breaks are incorrectly preserved in the converted Markdown output, when they should be normalized to a single space. These line breaks are purely cosmetic in the HTML source and should not affect the rendered text.
Input document (lorem.html)
<!doctype html><htmllang="en"><head><metacharset="UTF-8" /><title>Lorem Ipsum</title></head><body><p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
</p></body></html>
Actual output
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
Expected output
Line breaks within HTML paragraph tags should be treated as whitespace and converted to single spaces in Markdown output:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
The root cause is that Docling's HTML backend splits paragraph text by newline characters, so cosmetic line breaks in HTML <p> tags become blank lines (new paragraphs) in Markdown output instead of being normalized to spaces. This logic is in HTMLDocumentBackend._handle_block and AnnotatedTextList.split_by_newline in docling/backend/html_backend.py—there's no step that collapses internal newlines to spaces before splitting, which is why you're seeing this behavior source.
To fix this, update the backend to normalize cosmetic newlines within <p> tags to single spaces before splitting or avoid splitting unless there's an explicit <br> tag. This keeps paragraphs as single text items and prevents extra blank lines in Markdown. There are no config options or released workarounds for this—it's a code change source.
Tests for this scenario don't currently exist, so adding or updating tests to ensure cosmetic newlines in <p> tags are normalized to spaces in Markdown output is recommended.
Activity
dosubot commentedon Jan 27, 2026
The root cause is that Docling's HTML backend splits paragraph text by newline characters, so cosmetic line breaks in HTML
<p>tags become blank lines (new paragraphs) in Markdown output instead of being normalized to spaces. This logic is inHTMLDocumentBackend._handle_blockandAnnotatedTextList.split_by_newlineindocling/backend/html_backend.py—there's no step that collapses internal newlines to spaces before splitting, which is why you're seeing this behavior source.To fix this, update the backend to normalize cosmetic newlines within
<p>tags to single spaces before splitting or avoid splitting unless there's an explicit<br>tag. This keeps paragraphs as single text items and prevents extra blank lines in Markdown. There are no config options or released workarounds for this—it's a code change source.Tests for this scenario don't currently exist, so adding or updating tests to ensure cosmetic newlines in
<p>tags are normalized to spaces in Markdown output is recommended.To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
ceberam commentedon Feb 2, 2026
Thanks @lukasberbuer for bringing up this issue.
We will address this topic in the more global effort of preserve spacing (docling-project/docling-core#458)