Skip to content

chat: fix body tag leaking into rendered markdown when content ends with code block#309336

Merged
roblourens merged 3 commits intomainfrom
agents/worthy-kangaroo
Apr 13, 2026
Merged

chat: fix body tag leaking into rendered markdown when content ends with code block#309336
roblourens merged 3 commits intomainfrom
agents/worthy-kangaroo

Conversation

@roblourens
Copy link
Copy Markdown
Member

When markdown content ends with a fenced code block, the closing backticks were immediately followed by </body> on the same line in the template string. CommonMark requires the closing fence to be on its own line, so </body> was being treated as part of the code block and rendered as visible text in chat responses.

Fix

Add \n\n before </body> in the markdown render template to ensure any trailing code fence is properly closed before the wrapper tag.

Test

Added a regression test that renders markdown ending with a fenced code block and asserts </body> does not appear in the rendered text content.

(Written by Copilot)

…ith code block

When markdown content ends with a fenced code block, the closing backticks
were immediately followed by </body> on the same line, so CommonMark didn't
recognize the fence as closed. Add \n\n before </body> to ensure proper
parsing. Add regression test.

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 13, 2026 01:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a markdown rendering edge case in the chat widget where a trailing fenced code block could accidentally consume the closing </body> wrapper tag and render it as visible text.

Changes:

  • Adds trailing blank lines before the closing </body> in the HTML-wrapped markdown template so a final code fence closes cleanly.
  • Adds a regression test ensuring </body> does not appear in rendered text when markdown ends with a fenced code block.
Show a summary per file
File Description
src/vs/workbench/contrib/chat/browser/widget/chatContentMarkdownRenderer.ts Adjusts the body-wrapping template to insert \n\n before </body> to avoid the closing tag being parsed as part of a trailing code fence.
src/vs/workbench/contrib/chat/test/browser/widget/chatMarkdownRenderer.test.ts Adds a regression test that renders markdown ending in a fenced code block and asserts </body> is not leaked into the rendered text.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Screenshot Changes

Base: a75ae92e Current: 92e6f5aa

Changed (4)

agentSessionsViewer/FailedWithDuration/Dark
Before After
before after
agentSessionsViewer/FailedWithDuration/Light
Before After
before after
agentSessionsViewer/CloudProvider/Dark
Before After
before after
agentSessionsViewer/CloudProvider/Light
Before After
before after

@roblourens roblourens marked this pull request as draft April 13, 2026 01:19
roblourens and others added 2 commits April 12, 2026 18:22
The extra \n\n before </body> changes rendered HTML output slightly,
so snapshot baselines need to be regenerated by CI.

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update snapshot files to reflect the extra \n\n before </body> in the
markdown template, which adds trailing whitespace before the closing
wrapper div in rendered HTML output.

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@roblourens roblourens marked this pull request as ready for review April 13, 2026 01:45
@roblourens roblourens enabled auto-merge (squash) April 13, 2026 01:45
@roblourens roblourens merged commit 1bf8b2d into main Apr 13, 2026
26 checks passed
@roblourens roblourens deleted the agents/worthy-kangaroo branch April 13, 2026 02:00
@vs-code-engineering vs-code-engineering bot added this to the 1.116.0 milestone Apr 13, 2026
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.

3 participants