Skip to content

fix(cli): preserve trailing block separators in streamed markdown (Fixes #3257) - #3312

Merged
Yeachan-Heo merged 1 commit into
mainfrom
lane/cc-issue-3257
Oct 12, 2026
Merged

Yeachan-Heo merged 1 commit into
mainfrom
lane/cc-issue-3257

Conversation

@Yeachan-Heo

Copy link
Copy Markdown
Contributor

Issue

Missing newlines before paragraphs and code blocks in streamed Markdown cause consecutive chunks to run together on the same line.

Solution

  • Refactors render_markdown() to use a new render_markdown_raw() helper that preserves trailing whitespace
  • Adds markdown_to_ansi_stream() for stream-aware rendering that preserves block-level element newlines
  • Updates MarkdownStreamState::push() to use markdown_to_ansi_stream() instead of markdown_to_ansi()
  • Adds test verifying streamed blocks remain visually separated

Test Results

  • New test stream_rendering_preserves_block_separators passes
  • All 35 render module tests pass
  • Change is isolated to render.rs

When markdown is streamed chunk-by-chunk, block-level elements (paragraphs,
headings, code blocks, lists) need trailing newlines to prevent consecutive
chunks from running together on the same line.

This fix:
- Refactors render_markdown() to use a new render_markdown_raw() helper
- Adds markdown_to_ansi_stream() for stream-aware rendering that preserves
  trailing newlines from block elements
- Updates MarkdownStreamState::push() to use markdown_to_ansi_stream()
  instead of markdown_to_ansi()
- Adds a test verifying that streamed blocks remain visually separated

Fixes #3257
@XinwangTao

Copy link
Copy Markdown

The markdown_to_ansi_stream() split is exactly the right shape — keeping the one-shot trim_end() for full renders while giving the streaming path a raw helper that preserves block separators means chunk boundaries no longer decide the output. 35 render tests passing covers the regression well.

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.

2 participants