Skip to content

Fix MarkdownRenderer blockquote child spacing - #472

Open
deepakganesh78 wants to merge 1 commit into
lepture:mainfrom
deepakganesh78:fix/issue368-blockquote-adjacent-blocks
Open

Fix MarkdownRenderer blockquote child spacing#472
deepakganesh78 wants to merge 1 commit into
lepture:mainfrom
deepakganesh78:fix/issue368-blockquote-adjacent-blocks

Conversation

@deepakganesh78

Copy link
Copy Markdown

Fixes #368

Reproduction

On current main, reformatting a block quote with adjacent child blocks inserts an extra quoted blank line:

import mistune
from mistune.renderers.markdown import MarkdownRenderer

md = mistune.create_markdown(renderer=MarkdownRenderer())
print(repr(md("> #### Lorem\n> Ipsum")))

Before this change the result was '> #### Lorem\n> \n> Ipsum\n'.

Root cause

MarkdownRenderer.block_quote() rendered its child tokens as top-level Markdown before adding quote markers. Top-level block renderers intentionally end blocks with blank separators, so adjacent child blocks inside the same quote gained an extra > line even when the parsed quote AST did not contain a blank_line token.

Fix

Render block quote children token-by-token and collapse only the structural separator between adjacent non-blank child tokens before applying the quote prefix. Explicit blank_line tokens are preserved, so quoted paragraph breaks continue to render with a quoted blank line.

Compatibility

This only changes MarkdownRenderer output for adjacent child blocks inside block quotes. HTML rendering and explicit blank lines within block quotes are unchanged.

Validation

  • python -m pytest tests\test_renderers.py::TestMarkdownRendererRoundTrip::test_block_quote_adjacent_child_blocks -q -> 1 passed
  • With the renderer fix reverted, the new regression test fails with '> #### Lorem\n> \n> Ipsum\n' != '> #### Lorem\n> Ipsum\n'
  • python -m pytest -> 765 passed
  • python -m ruff check . -> All checks passed
  • python -m mypy -> Success: no issues found in 38 source files

Avoid inserting top-level blank separators between adjacent child blocks when rendering Markdown block quotes, while preserving explicit blank_line tokens inside the quote.

Fixes lepture#368

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.21%. Comparing base (75cab78) to head (644448d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #472      +/-   ##
==========================================
+ Coverage   91.18%   91.21%   +0.02%     
==========================================
  Files          36       36              
  Lines        3631     3642      +11     
  Branches      677      679       +2     
==========================================
+ Hits         3311     3322      +11     
  Misses        193      193              
  Partials      127      127              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

parse -> render loop causes newlines within quote blocks

1 participant