feat(ui): 会话正文里的围栏代码块也上色
md 渲染只做了 marked → HTML + 复制按钮,聊天里贴的 ```js 一直是无色纯文本; 代码预览和 Git diff 都上色了,唯独对话主体没有。 历史渲染在 appendMessagesDom 收口处、流式在 stream.js 两处(收尾整块重排与 分页追加)各补一次 pvHighlightMdCode;token 配色的选择器前缀加上 .md(聊天气泡 的 markdown 容器),与预览共用同一套 GitHub 配色。
This commit is contained in:
@@ -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; }
|
||||
|
||||
@@ -380,6 +380,7 @@
|
||||
}
|
||||
// 历史渲染收口:给本轮新渲染出的代码块补复制按钮(目标可能是分页离屏容器,装饰后再随节点搬迁)
|
||||
decorateCodePre(target);
|
||||
pvHighlightMdCode(target); // 对话正文里的围栏代码块也上色(与预览同一套)
|
||||
return { closeArc };
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user