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

Aperta
#2,642 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@patrick-5546 ci sta già lavorando.

Dal 6/10/2026.

  • #2643 di @patrick-5546 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
markdown, python
Ambito
tooling

Direzione di ricerca

Start from the "Normalize the content" step in _markitdown.py where trailing whitespace is stripped from every output line, and reproduce with the HTML snippet in the issue body to confirm Line one\nLine two. Decide whether to preserve lines ending in two or more spaces (approach of open PR #2559) or otherwise exempt hard breaks, and check the fenced-code-block concern from #2528/#2529/#2633. Done means the snippet yields 'Line one\\\nLine two' and a DOCX <w:br/> round-trips, with tests added. Note two open PRs (#2643, #2662) already target this issue, so coordinate before starting.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
198k
Fork
15k
Merge medio
2h 16m
PR unite (30g)
9

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/markitdown

Tutte le issue di microsoft/markitdown

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.