Repository navigation
feat: 支持可配置的聊天 HTML/CSS 内联预览 - #1041
Merged
xintaofei merged 7 commits intoOct 27, 2026
Merged
Conversation
The chat preview's sanitizer removed `href` but kept SVG's `xlink:href` and `<set>`/`<animate>` elements that write a link target, so a click could still navigate the sandboxed frame to an outside page, where CSP no longer applies. Any attribute named `href` or `*:href` is now dropped unless it points into the document itself (`#id`), which also keeps SVG `<use>` and gradient references and in-page anchors working, and animations that target a link are removed.
The theme tokens, the size reporter and the theme reader moved from the Codex visualize card to html-preview-frame.ts without their comments, which stayed behind in the card above unrelated declarations.
With the setting on, every assistant reply was drawn in Streamdown's streaming mode even after it finished, so finished replies lost per-paragraph text direction and left-to-right code, reference-style links stayed literal text, and json-render cards stayed in their loading state. Finished replies render statically again; a preview that mounts anew when its reply stops streaming comes back from a cache of the built document, its measured height and the view the reader picked. Only self-contained HTML becomes a preview: a fragment's root has to close inside the run of HTML blocks it starts. Tags that wrap Markdown (a <details> around a list) or never close before Markdown are left to Markdown instead of swallowing the rest of the reply into a code block, and a synthetic closing fence always ends its line. While streaming, a fragment is final only once the block after it is known, so a sibling root on the next line still joins it and the finished output matches processing the whole text at once. A closed HTML fence always previews, and an agent-written codeg-html-pending fence shows as code once the reply is done. Streaming no longer re-parses the whole reply on every delta: text with no line that can open HTML skips the parse, the parse covers block structure only, everything before the last block is sealed, and an open fence at the end is only watched for its closing line. The preview nonce comes from the utils randomUUID, which has a fallback for plain-HTTP origins where crypto.randomUUID is missing, and over code the Code/Preview switch sits clear of the code block's copy and download buttons.
A preview that mounted from the frame cache relied on the cache for its document; once 32 newer previews pushed its entry out, its next render fell back to "Generating HTML…" for good. Previews on screen now pin their entries, and eviction passes over pinned ones.
Settling text at block boundaries also cut the Markdown around fragments into pieces for the math-delimiter rewrite, so a `\[ … \]` across a blank line streamed differently from the same reply processed at once. Only the structure is settled now: output is kept up to the last settled fragment, and the Markdown after it is kept raw and transformed whole. The settled state also outlived edits that were not appends, keeping decisions made for text that had changed; any such edit now starts over.
Collaborator
|
codeg work task |
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.
原问题
AI 在回复中输出 HTML 代码块时,用户只能阅读源码,无法直接查看卡片、对比矩阵等排版效果。自包含的 HTML/CSS 片段与 Markdown 正文混排时,也缺少对应的预览能力。
Closes #657
改动
html/htm代码块以及顶层自包含 HTML/CSS 片段,支持与 Markdown 混排,并可切换查看源码。测试
tsc --noEmit、修改文件的 ESLint、Prettier、git diff --check均通过;生产构建成功,静态导出 37 页。截图
图一:设置开关
图二:对话内预览