fix(webchat): render standalone HTML replies as code blocks#6074
fix(webchat): render standalone HTML replies as code blocks#6074stablegenius49 wants to merge 1 commit intoAstrBotDevs:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the chat message rendering by intelligently handling plain-text replies that contain full HTML structures. Previously, such content might have been misinterpreted or rendered incorrectly by the markdown parser. The changes introduce a preprocessing step to identify these HTML documents and explicitly format them as HTML code blocks, ensuring they are displayed as intended without affecting the rendering of standard markdown or existing code fences. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey - 我在这里给出一些整体性的反馈:
- 在
normalizeMarkdownContent中,生成的代码块使用了四个反引号(```````),而不是通常的三个;除非你的 Markdown 渲染器明确需要使用四反引号代码块,否则这很可能会导致渲染不正确,应当与MarkdownRender` 期望的代码块格式保持一致。 isMarkdownCodeFence只检查(去除首尾空白后)字符串最开头位置的代码块标记,因此如果在代码块标记前存在任何前导字符(例如注释或 BOM),内容就会被当作 HTML 重新包装;如果在实际使用中可能出现这种情况,建议让这段检测逻辑更健壮一些。
面向 AI Agent 的提示词
Please address the comments from this code review:
## Overall Comments
- In `normalizeMarkdownContent`, the generated code fence uses four backticks (```\`\`\`\``) rather than the usual three; unless your markdown renderer specifically expects 4-backtick fences, this is likely to render incorrectly and should be aligned with whatever fence style `MarkdownRender` expects.
- `isMarkdownCodeFence` only checks for fences at the very beginning of the (trimmed) string, so any leading characters (e.g., comments or BOM) before a fence will cause the content to be rewrapped as HTML; consider making the detection a bit more robust if such cases are possible in practice.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English
Hey - I've left some high level feedback:
- In
normalizeMarkdownContent, the generated code fence uses four backticks (```````) rather than the usual three; unless your markdown renderer specifically expects 4-backtick fences, this is likely to render incorrectly and should be aligned with whatever fence styleMarkdownRender` expects. isMarkdownCodeFenceonly checks for fences at the very beginning of the (trimmed) string, so any leading characters (e.g., comments or BOM) before a fence will cause the content to be rewrapped as HTML; consider making the detection a bit more robust if such cases are possible in practice.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `normalizeMarkdownContent`, the generated code fence uses four backticks (```\`\`\`\``) rather than the usual three; unless your markdown renderer specifically expects 4-backtick fences, this is likely to render incorrectly and should be aligned with whatever fence style `MarkdownRender` expects.
- `isMarkdownCodeFence` only checks for fences at the very beginning of the (trimmed) string, so any leading characters (e.g., comments or BOM) before a fence will cause the content to be rewrapped as HTML; consider making the detection a bit more robust if such cases are possible in practice.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to detect and render standalone HTML documents in chat replies as code blocks, preventing them from being interpreted by the browser. The implementation adds helper functions to identify potential HTML content and wraps it in a markdown code fence. My review includes a suggestion to improve the accuracy of the HTML detection logic by ensuring it only matches content that starts with HTML tags, thus avoiding false positives.
| const looksLikeStandaloneHtml = (text) => { | ||
| const normalized = text.trim(); | ||
| if (!normalized) return false; | ||
| if (!/(<!doctype\s+html|<html\b|<head\b|<body\b)/i.test(normalized)) return false; |
There was a problem hiding this comment.
To more accurately detect standalone HTML documents, it's better to anchor the regex to the start of the string. This ensures that we only match text that begins with an HTML tag, preventing false positives on content that merely contains HTML tags somewhere in the middle.
if (!/^(<!doctype\s+html|<html\b|<head\b|<body\b)/i.test(normalized)) return false;
Summary
Verification
corepack pnpm exec vue-tsc --noEmitcorepack pnpm exec vite buildCloses #5988
Summary by Sourcery
规范对包含完整 HTML 文档的纯文本聊天回复的渲染方式,使其以代码形式显示,而不是被当作可解释的 HTML。
Bug Fixes:
Enhancements:
Original summary in English
Summary by Sourcery
Normalize rendering of plain-text chat replies that contain full HTML documents so they are displayed as code rather than interpreted HTML.
Bug Fixes:
Enhancements: