修复: Web 端手机查看 AI 回复撑宽页面 + 图片无法显示#200
Merged
riba2534 merged 1 commit intoriba2534:mainfrom Mar 18, 2026
Merged
Conversation
## 问题 1. AI 回复中的表格使用 `w-max`(width: max-content)+ `whitespace-nowrap`, 在手机屏幕上内容超出视口宽度,导致整个页面被撑宽可水平滚动。 2. AI 回复中的 HTML 图片标签(如 `<img src="...">`)无法渲染为实际图片, 因为缺少 `rehype-raw` 插件,react-markdown 默认将 HTML 标签当纯文本显示。 ## 修复方案 ### 手机端宽度(MarkdownRenderer.tsx) - 移除表格的 `w-max` 样式,保留 `min-w-full` 确保表格至少填满容器宽度 - 移除 `th`/`td` 的 `whitespace-nowrap break-normal`,改为 `break-words` 允许单元格文本在手机端自然换行,避免表格无限撑宽 - 表格外层容器的 `overflow-x-auto` 仍保留,宽表格可水平滚动 ### 图片显示(MarkdownRenderer.tsx + package.json) - 新增 `rehype-raw` 依赖,支持解析 markdown 中嵌入的 HTML 标签 - 将 `rehype-raw` 插入 rehype 管道最前端(sanitize 之前), 确保 HTML 先被解析、再被 `rehype-sanitize` 安全过滤 - 显式声明 `img` 标签允许的属性列表(src/alt/width/height/loading/title), 避免依赖 defaultSchema 全局属性的隐式继承 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
我是手机端web用户,感觉页面问题还挺多的,想帮忙改一下 |
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.
问题描述
Web 端在手机上查看 AI 回复时存在两个问题:
w-max(width: max-content)+whitespace-nowrap,在手机窄屏上表格内容超出视口宽度,导致整个页面可水平滚动。<img>标签,由于缺少rehype-raw插件,react-markdown默认将 HTML 标签当作纯文本显示而非渲染为实际图片。同时rehype-sanitize的img属性白名单依赖全局*属性的隐式继承,不够稳健。修复方案
web/src/components/chat/MarkdownRenderer.tsx手机端表格宽度:
w-max样式,保留min-w-full确保表格至少填满容器宽度th/td单元格的whitespace-nowrap break-normal改为break-words,允许文本在手机端自然换行overflow-x-auto仍保留,内容确实较宽时仍可水平滚动图片渲染:
rehype-raw插件(位于rehype-sanitize之前),支持解析 Markdown 中嵌入的 HTML 标签img标签允许的属性列表(src/alt/width/height/loading/longDesc/title),不再依赖defaultSchema全局属性的隐式继承web/package.jsonrehype-raw@^7.0.0依赖