Skip to content

Hard line breaks are lost: <br> and Word line breaks become spaces #2642

Open

Description

markdownify writes a <br> as two trailing spaces, which is a Markdown hard line break. MarkItDown.convert() then strips trailing whitespace from every output line (the "Normalize the content" step in _markitdown.py). Every hard line break therefore becomes a soft break, which renders as a space. This affects every converter that renders HTML through markdownify, including HTML, DOCX (Word line breaks, Shift+Enter) and RSS. It also affects the OCR text that markitdown-ocr adds for images in DOCX, PPTX and XLSX files.

import io
from markitdown import MarkItDown

html = b"<p>Line one<br>Line two</p>"
print(repr(MarkItDown().convert_stream(io.BytesIO(html), file_extension=".html").markdown))

Actual: 'Line one\nLine two', which renders as "Line one Line two".

Expected: a hard line break, such as 'Line one\\\nLine two'.

The attached DOCX has one paragraph containing a Word line break (<w:br/>) and gives the same result.

markitdown-line-breaks.docx

Related: #2528 reports that the same normalization removes trailing spaces in fenced code blocks. Its PRs, #2529 and #2633, change only code blocks. Open PR #2559 would fix this by keeping lines that end in two or more spaces during the normalization.

Environment: markitdown 0.1.8 (main 4cc9fa1), markdownify 1.2.3, Python 3.14.8, Ubuntu 24.04.5 LTS.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions