Skip to content

Fix Markdown closing fence handling#25310

Merged
MichaReiser merged 4 commits into
astral-sh:mainfrom
fallintoplace:fix-markdown-closing-fences
May 22, 2026
Merged

Fix Markdown closing fence handling#25310
MichaReiser merged 4 commits into
astral-sh:mainfrom
fallintoplace:fix-markdown-closing-fences

Conversation

@fallintoplace
Copy link
Copy Markdown
Contributor

Summary

  • Accept Markdown closing fences that use the same fence character and are at least as long as the opening fence.
  • Reject candidate closing fences that have non-whitespace trailing content after the fence.
  • Add regression tests for longer valid closing fences and invalid closing fences with info strings.

Fixes #25309.

Test

  • cargo test -p ruff_markdown
  • uvx prek run --files crates/ruff_markdown/src/lib.rs
  • cargo run --bin ruff -- format --preview --isolated --stdin-filename repro.md -

@fallintoplace fallintoplace marked this pull request as ready for review May 21, 2026 23:47
Comment thread crates/ruff_markdown/src/lib.rs Outdated
.take_while(|&&byte| byte == fence_byte)
.count();

fence_len >= opening_fence.len() && line[fence_len..].chars().all(is_python_whitespace)
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser May 22, 2026

Choose a reason for hiding this comment

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

Can you say more about why you use is_python_whitespace here over char::is_whitespace? E.g. is_python_whitespace also includes form feeds, which I think is incorrect here

@MichaReiser MichaReiser added bug Something isn't working formatter Related to the formatter preview Related to preview mode features labels May 22, 2026
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thank you

@MichaReiser MichaReiser merged commit 0cdb61a into astral-sh:main May 22, 2026
44 checks passed
thejchap pushed a commit to thejchap/ruff that referenced this pull request May 23, 2026
anishgirianish pushed a commit to anishgirianish/ruff that referenced this pull request May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working formatter Related to the formatter preview Related to preview mode features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown formatter mishandles closing code fences

2 participants