Skip to content

fix: preserve Markdown hard line breaks - #2559

Open
Maciej Zmitrukiewicz (MaciejZet) wants to merge 1 commit into
microsoft:mainfrom
MaciejZet:fix/preserve-markdown-hard-breaks
Open

Maciej Zmitrukiewicz (MaciejZet) wants to merge 1 commit into
microsoft:mainfrom
MaciejZet:fix/preserve-markdown-hard-breaks

Conversation

@MaciejZet

@MaciejZet Maciej Zmitrukiewicz (MaciejZet) commented Sep 27, 2026 •

Copy link
Copy Markdown

Summary

  • MarkItDown._convert was stripping every trailing space, so a CommonMark hard break (two or more spaces before a newline) became a soft break.
  • Lines that end with at least two spaces are now kept. A single trailing space, a trailing tab, and a whitespace-only line are still removed. Runs of blank lines are still collapsed.
  • HTML <br> and DOCX <w:br/> are emitted by markdownify as those two spaces, and current upstream expectations now preserve the hard break.

The branch has been rebased onto the current upstream main to resolve the merge conflict. The fix is limited to the normalization helper and its regression coverage; unrelated upstream test refactors were preserved.

Test plan

  • Full packages/markitdown/tests on Python 3.12 with the all extra: 1124 passed, 12 skipped
  • Dedicated hard-break regression: 29 passed
  • Updated HTML and DOCX expectations for generated hard breaks

Refs #2559

@MaciejZet

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant