chat: fix body tag leaking into rendered markdown when content ends with code block#309336
Merged
roblourens merged 3 commits intomainfrom Apr 13, 2026
Merged
chat: fix body tag leaking into rendered markdown when content ends with code block#309336roblourens merged 3 commits intomainfrom
roblourens merged 3 commits intomainfrom
Conversation
…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>
Contributor
There was a problem hiding this comment.
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
Contributor
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>
DonJayamanne
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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\nbefore</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)