From 0adc6d83829d26d810cfff27ccd22e0ce953e8de Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 6 Jul 2026 16:13:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E6=9A=97=E8=89=B2=20type=20?= =?UTF-8?q?=E8=89=B2=E5=80=BC=E4=BF=AE=E6=AD=A3=20+=20extractLang=20?= =?UTF-8?q?=E5=B0=8F=E5=86=99=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - .dark .hljs-type/.hljs-title.class_ 由 #8839ef(紫) 改为 #f9e2af(黄), 与 spec 表、官方 @catppuccin/highlightjs、读者侧 highlight.css 三处对齐 - extractLang 加 toLowerCase,与后端 parse_fence_info(languages.rs:85)对齐, 避免大写语言名触发 lowlight Unknown language 抛错 --- libs/tiptap-editor/src/__tests__/highlight.test.ts | 2 ++ libs/tiptap-editor/src/highlight.ts | 10 ++++++---- libs/tiptap-editor/src/style.css | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libs/tiptap-editor/src/__tests__/highlight.test.ts b/libs/tiptap-editor/src/__tests__/highlight.test.ts index 6546a6c..397c380 100644 --- a/libs/tiptap-editor/src/__tests__/highlight.test.ts +++ b/libs/tiptap-editor/src/__tests__/highlight.test.ts @@ -14,6 +14,8 @@ describe('extractLang', () => { [' python ', 'python', '前后空格(trim)'], ['', '', '空字符串'], [' ', '', '纯空格'], + ['PYTHON', 'python', '大写小写化(与后端对齐)'], + ['Python Runnable', 'python', '混合大小写'], ])('%s → %s (%s)', (input, expected) => { expect(extractLang(input)).toBe(expected); }); diff --git a/libs/tiptap-editor/src/highlight.ts b/libs/tiptap-editor/src/highlight.ts index ce7a524..e0b0d54 100644 --- a/libs/tiptap-editor/src/highlight.ts +++ b/libs/tiptap-editor/src/highlight.ts @@ -3,13 +3,15 @@ import { common, createLowlight } from 'lowlight'; const base = createLowlight(common); /** - * 从完整 fence info string 提取语言名(首个 token)。 + * 从完整 fence info string 提取语言名(首个 token,小写化)。 * - * 与后端 parse_fence_info(src/api/code_runner/languages.rs:80)对齐: - * info string 形如 `python runnable {"timeout_secs":10}`,语言是首个空白分隔的 token。 + * 与后端 parse_fence_info(src/api/code_runner/languages.rs:85)对齐: + * info string 形如 `python runnable {"timeout_secs":10}`,语言是首个空白分隔的 token, + * 再 to_lowercase(lowlight 注册名均为小写,大写会导致 Unknown language 抛错)。 */ export function extractLang(info: string): string { - return info.trim().split(/\s+/)[0] || ''; + const first = info.trim().split(/\s+/)[0]; + return first ? first.toLowerCase() : ''; } /** diff --git a/libs/tiptap-editor/src/style.css b/libs/tiptap-editor/src/style.css index 2d6a77c..10d7656 100644 --- a/libs/tiptap-editor/src/style.css +++ b/libs/tiptap-editor/src/style.css @@ -903,7 +903,7 @@ } .dark .tiptap-editor pre code .hljs-type, .dark .tiptap-editor pre code .hljs-title.class_ { - color: #8839ef; + color: #f9e2af; } .dark .tiptap-editor pre code .hljs-built_in, .dark .tiptap-editor pre code .hljs-doctag {