Skip to content

fix(md): keep the first-line indentation of code blocks - #4487

Merged
PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
ankit2235:fix/md-code-block-indentation
Oct 2, 2026
Merged

PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
ankit2235:fix/md-code-block-indentation

Conversation

@ankit2235

@ankit2235 ankit2235 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

The Markdown backend called .strip() on code block content, which removed the leading indentation of the first line while later lines kept theirs. The relative indentation changed, so the code itself was altered: an indented YAML snippet changed structure, and an indented Python snippet no longer parsed.

This trims only blank lines before the code and whitespace after it (lstrip("\n").rstrip()), keeping the first line's indentation. It is the same trimming PR #3891 applies to HTML <pre>. Code blocks whose first line is not indented are unchanged, and whitespace-only blocks are still skipped.

The new test covers a fenced block, an indented (non-fenced) block, and a fenced block that starts with a blank line (which is still dropped). It fails on main and passes with this change. All existing Markdown groundtruth tests pass unchanged.

Issue resolved by this Pull Request:
Resolves #4485

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 1, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

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

@mergify

mergify Bot commented Oct 1, 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)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@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!

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 strips the first-line indentation of code blocks

2 participants