feat(ui): 代码预览接入 Prism 语法高亮,md 代码块与 Git diff 共用一套配色
js/json/yml/sh/py 这类文件原来只有行号、没有颜色。vendor 里加 prism.min.js (core + 20 种常用语言,52KB / gzip 18.7KB),UMD 直接 <script> 引入,与 marked 同一种加载方式,不需要构建。 代码预览是整块高亮后再按行拆:pvSplitHighlighted 维护一个打开的 span 栈, 行尾补 </span>、下一行行首重开同名标签。逐行调 Prism.highlight 会把多行注释、 三引号字符串、模板字符串切花;拆完行数与原文对不上时退回纯文本,保证行号不错位。 配色(GitHub 亮色系)用 :is(.pv-code, .pv-doc, .vcs-line) 覆盖三处: - 代码预览 .pv-code - md 里的围栏代码块:pvHighlightMdCode 用 highlightElement,只处理标了 language-xx 且语言已打包的块,没有语言标记的保持纯文本 - Git 面板 diff:逐行着色(diff 是片段,跨行 token 本来也拼不完整), 超过 2000 行的 patch 不上色,避免同步高亮把面板卡住
This commit is contained in:
@@ -1674,6 +1674,18 @@ body.pv-max .pv-pre { max-width: none; } /* 放大时源码面板同样铺满 */
|
||||
}
|
||||
/* 放大预览时铺满:#pv-pane 已经是全屏,内容别再卡在 920px 的阅读宽度里 */
|
||||
body.pv-max .pv-code { max-width: none; padding-left: 16px; padding-right: 16px; }
|
||||
/* 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; }
|
||||
.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; }
|
||||
|
||||
Reference in New Issue
Block a user