From 0529991ba143b9ceefb6ad1b7b75be60e04b9bda Mon Sep 17 00:00:00 2001 From: kicer Date: Fri, 13 Nov 2026 17:11:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E4=BC=9A=E8=AF=9D=E6=AD=A3?= =?UTF-8?q?=E6=96=87=E9=87=8C=E7=9A=84=E5=9B=B4=E6=A0=8F=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=9D=97=E4=B9=9F=E4=B8=8A=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit md 渲染只做了 marked → HTML + 复制按钮,聊天里贴的 ```js 一直是无色纯文本; 代码预览和 Git diff 都上色了,唯独对话主体没有。 历史渲染在 appendMessagesDom 收口处、流式在 stream.js 两处(收尾整块重排与 分页追加)各补一次 pvHighlightMdCode;token 配色的选择器前缀加上 .md(聊天气泡 的 markdown 容器),与预览共用同一套 GitHub 配色。 --- app/server/public/css/style.css | 24 ++++++++++++------------ app/server/public/js/chat.js | 1 + app/server/public/js/stream.js | 2 ++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index 753bd8b..ba07ab0 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -1684,18 +1684,18 @@ body.pv-max .pv-code { max-width: none; padding-left: 16px; padding-right: 16px; @media (max-width: 959px) { .pv-cl::before { width: 28px; margin-right: 6px; padding-right: 4px; } } -/* Prism token 配色(GitHub 亮色系):代码预览、md 围栏代码块、Git 面板 diff 共用 */ -:is(.pv-code, .pv-doc, .vcs-line) :is(.token.comment, .token.prolog, .token.doctype, .token.cdata) { color: #6a737d; font-style: italic; } -:is(.pv-code, .pv-doc, .vcs-line) .token.punctuation { color: #24292e; } -:is(.pv-code, .pv-doc, .vcs-line) .token.namespace { opacity: .7; } -:is(.pv-code, .pv-doc, .vcs-line) :is(.token.property, .token.tag, .token.boolean, .token.number, .token.constant, .token.symbol, .token.deleted) { color: #005cc5; } -:is(.pv-code, .pv-doc, .vcs-line) :is(.token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted) { color: #032f62; } -:is(.pv-code, .pv-doc, .vcs-line) :is(.token.operator, .token.entity, .token.url) { color: #d73a49; } -:is(.pv-code, .pv-doc, .vcs-line) :is(.token.atrule, .token.attr-value, .token.keyword) { color: #d73a49; } -:is(.pv-code, .pv-doc, .vcs-line) :is(.token.function, .token.class-name) { color: #6f42c1; } -:is(.pv-code, .pv-doc, .vcs-line) :is(.token.regex, .token.important, .token.variable) { color: #e36209; } -:is(.pv-code, .pv-doc, .vcs-line) .token.bold { font-weight: 600; } -:is(.pv-code, .pv-doc, .vcs-line) .token.italic { font-style: italic; } +/* Prism token 配色(GitHub 亮色系):代码预览、md 围栏代码块(预览与对话正文)、Git 面板 diff 共用 */ +:is(.pv-code, .pv-doc, .vcs-line, .md) :is(.token.comment, .token.prolog, .token.doctype, .token.cdata) { color: #6a737d; font-style: italic; } +:is(.pv-code, .pv-doc, .vcs-line, .md) .token.punctuation { color: #24292e; } +:is(.pv-code, .pv-doc, .vcs-line, .md) .token.namespace { opacity: .7; } +:is(.pv-code, .pv-doc, .vcs-line, .md) :is(.token.property, .token.tag, .token.boolean, .token.number, .token.constant, .token.symbol, .token.deleted) { color: #005cc5; } +:is(.pv-code, .pv-doc, .vcs-line, .md) :is(.token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted) { color: #032f62; } +:is(.pv-code, .pv-doc, .vcs-line, .md) :is(.token.operator, .token.entity, .token.url) { color: #d73a49; } +:is(.pv-code, .pv-doc, .vcs-line, .md) :is(.token.atrule, .token.attr-value, .token.keyword) { color: #d73a49; } +:is(.pv-code, .pv-doc, .vcs-line, .md) :is(.token.function, .token.class-name) { color: #6f42c1; } +:is(.pv-code, .pv-doc, .vcs-line, .md) :is(.token.regex, .token.important, .token.variable) { color: #e36209; } +:is(.pv-code, .pv-doc, .vcs-line, .md) .token.bold { font-weight: 600; } +:is(.pv-code, .pv-doc, .vcs-line, .md) .token.italic { font-style: italic; } .pv-trunc { max-width: 880px; margin: 12px auto 0; padding: 0 20px; font-size: 12px; color: var(--gray-light); } .pv-loading.inline { position: static; background: transparent; padding: 56px 0; } .pv-none { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 44px 24px; text-align: center; } diff --git a/app/server/public/js/chat.js b/app/server/public/js/chat.js index 7965a1d..ef7910c 100644 --- a/app/server/public/js/chat.js +++ b/app/server/public/js/chat.js @@ -380,6 +380,7 @@ } // 历史渲染收口:给本轮新渲染出的代码块补复制按钮(目标可能是分页离屏容器,装饰后再随节点搬迁) decorateCodePre(target); + pvHighlightMdCode(target); // 对话正文里的围栏代码块也上色(与预览同一套) return { closeArc }; } diff --git a/app/server/public/js/stream.js b/app/server/public/js/stream.js index 1009c5d..5267883 100644 --- a/app/server/public/js/stream.js +++ b/app/server/public/js/stream.js @@ -313,6 +313,7 @@ state.streamEl.className = 'bubble-ai' + (r.fmt ? ' md' : ''); // 增量期间是纯文本,收尾统一换 md 排版 state.streamEl.innerHTML = r.html; decorateCodePre(state.streamEl); // 流式期间不插按钮(每帧整块换 innerHTML),收尾统一装饰一次 + pvHighlightMdCode(state.streamEl); // 围栏代码块上色 } else { // 无文本时去掉气泡(纯工具调用/纯思考也要保留思考面板) state.streamEl.remove(); @@ -326,6 +327,7 @@ bubble.className = 'bubble-ai' + (r.fmt ? ' md' : ''); bubble.innerHTML = r.html; decorateCodePre(bubble); + pvHighlightMdCode(bubble); state.streamWrap.appendChild(bubble); } // 「压缩」总结回合的最终答复(后端已保证只有压缩回合里首条无工具调用的收尾回复才带 is_summary,