Skip to content

HTML line breaks incorrectly preserved in Markdown output #2922

Open

Description

@lukasberbuer

Bug

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>
<html lang="en">
  <head>
    <meta charset="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.

Steps to reproduce

$ docling lorem.html --to md

Docling version

Docling version: 2.70.0
Docling Core version: 2.60.2
Docling IBM Models version: 3.11.0
Docling Parse version: 4.7.3
Python: cpython-314 (3.14.2)
Platform: Windows-11-10.0.26200-SP0

Python version

Python 3.14.2

Activity

  1. dosubot commented on Jan 27, 2026

    @dosubot

    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.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about docling with Dosu Add Dosu to your team

  2. self-assigned this
    on Feb 2, 2026
  3. added theissue type on Feb 2, 2026
  4. ceberam commented on Feb 2, 2026

    @ceberam
    Member

    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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghtmlissue related to html backend

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions