Skip to content

fix(md): drop whitespace-only lines before code block content - #4543

Merged
DanielNg0729 merged 1 commit into
docling-project:mainfrom
ankit2235:fix/md-code-whitespace-first-line
Oct 4, 2026
Merged

DanielNg0729 merged 1 commit into
docling-project:mainfrom
ankit2235:fix/md-code-whitespace-first-line

Conversation

@ankit2235

@ankit2235 ankit2235 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #4487. The Markdown backend trimmed code block content with lstrip("\n").rstrip(), so a first line holding only spaces survived and the code item started with a line of whitespace (' \n x = 1').

This uses the same trimming as the LaTeX backend after #4502 (suggested in review by @DanielNg0729): leading lines that hold only whitespace are dropped, and the first code line keeps its indentation.

The existing test_code_block_keeps_first_line_indentation gets a fourth block with a spaces-only first line. It fails on main and passes with this change; the other Markdown tests, including the groundtruth comparison, pass unchanged.

Issue resolved by this Pull Request:
Resolves #4541

Checklist:

  • Documentation has been updated, if necessary. (not needed)
  • Examples have been added, if necessary. (not needed)
  • Tests have been added, if necessary.

Signed-off-by: Ankit Kumar <ankitkumar19473@gmail.com>
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @ankit2235, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@PeterStaar-IBM
PeterStaar-IBM self-requested a review October 4, 2026 06:21

@PeterStaar-IBM PeterStaar-IBM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@DanielNg0729
DanielNg0729 merged commit eda5b5f into docling-project:main Oct 4, 2026
26 checks passed
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.

Markdown backend keeps a whitespace-only first line in code blocks

3 participants