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 {