fix: render standalone HTML documents consistently in WebChat#6157
fix: render standalone HTML documents consistently in WebChat#6157tsubasakong wants to merge 2 commits 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 addresses an issue in WebChat where standalone HTML documents sent as assistant messages were partially rendered as interactive DOM elements. The changes introduce a mechanism to identify these full HTML documents and preprocess them by wrapping them in Markdown HTML code blocks. This ensures that such responses are consistently displayed as code, preventing unintended live rendering, while maintaining the expected behavior for messages with mixed content. Highlights
Changelog
Activity
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 - 我在这里给出一些整体性的反馈:
- 在将检测到的完整 HTML 文档包裹进
html 代码块之前,建议对其中已有的三反引号进行转义或转换,否则如果内容中包含(例如脚本里),可能会破坏最终生成的 Markdown 结构。 - 如果其他组件也会把助手的纯文本作为 Markdown 渲染,建议考虑将
normalizeMarkdownContent和FULL_HTML_DOCUMENT_RE抽到一个共享的工具模块中,这样可以在整个应用中保持 HTML 文档检测逻辑的一致性。
供 AI 代理使用的提示词
Please address the comments from this code review:
## Overall Comments
- Consider escaping or transforming any existing triple backticks inside a detected full HTML document before wrapping it in a ```html fenced block, otherwise content that includes ``` (e.g., in scripts) could break the resulting markdown structure.
- If other components also render assistant plain-text as markdown, it may be worth moving `normalizeMarkdownContent` and `FULL_HTML_DOCUMENT_RE` into a shared utility to keep the HTML-document detection logic consistent across the app.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进后续的代码评审。
Original comment in English
Hey - I've left some high level feedback:
- Consider escaping or transforming any existing triple backticks inside a detected full HTML document before wrapping it in a
html fenced block, otherwise content that includes(e.g., in scripts) could break the resulting markdown structure. - If other components also render assistant plain-text as markdown, it may be worth moving
normalizeMarkdownContentandFULL_HTML_DOCUMENT_REinto a shared utility to keep the HTML-document detection logic consistent across the app.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider escaping or transforming any existing triple backticks inside a detected full HTML document before wrapping it in a ```html fenced block, otherwise content that includes ``` (e.g., in scripts) could break the resulting markdown structure.
- If other components also render assistant plain-text as markdown, it may be worth moving `normalizeMarkdownContent` and `FULL_HTML_DOCUMENT_RE` into a shared utility to keep the HTML-document detection logic consistent across the app.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 addresses an issue where standalone HTML documents were being partially rendered in WebChat. The fix involves detecting these documents using a regular expression and wrapping them in a markdown HTML code block. The approach is sound and effectively solves the problem. I have one suggestion to improve the regular expression for better readability and maintainability by using a more modern syntax.
| emit('download-file', file); | ||
| }; | ||
|
|
||
| const FULL_HTML_DOCUMENT_RE = /^\s*(?:<!doctype\s+html[^>]*>\s*)?<html\b[\s\S]*<\/html>\s*$/i; |
There was a problem hiding this comment.
For improved readability and to align with modern JavaScript standards, consider using the s (dotAll) flag in your regular expression. This flag allows . to match newline characters, making the [\s\S] construct unnecessary. The resulting regex is cleaner and easier to understand.
const FULL_HTML_DOCUMENT_RE = /^\s*(?:<!doctype\s+html[^>]*>\s*)?<html\b.*<\/html>\s*$/is;
|
already fixed in #6074, thanks! |
Fixes #5988.
Modifications / 改动点
Detect plain-text assistant messages that are actually standalone HTML documents.
Wrap those full-document HTML responses in an
htmlfenced code block before passing them toMarkdownRender, so WebChat shows the whole page consistently as code instead of partially rendering live form elements.Leave mixed-content messages unchanged, so normal markdown / inline HTML behavior is unaffected.
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Verification steps:
<!DOCTYPE html> ... </html>page).Test logs:
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Summary by Sourcery
错误修复:
Original summary in English
Summary by Sourcery
Bug Fixes: