Skip to content

Commit 971bb63

Browse files
Fix shiki type errors by using bundled theme/lang imports
Use `bundledThemes` and `bundledLanguages` from shiki's properly typed barrel exports instead of direct subpath imports (`shiki/langs/javascript`) which lack type declarations and fail svelte-check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 51e6161 commit 971bb63

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

web/src/lib/prosemirror/code-highlight.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
type HighlighterCore,
99
} from 'shiki/core';
1010
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
11+
import { bundledThemes } from 'shiki/themes';
12+
import { bundledLanguages } from 'shiki/langs';
1113

1214
type ParserFn = (options: {
1315
content: string;
@@ -16,6 +18,12 @@ type ParserFn = (options: {
1618
size: number;
1719
}) => Decoration[] | Promise<void>;
1820

21+
const LANGS: (keyof typeof bundledLanguages)[] = [
22+
'javascript', 'typescript', 'python', 'bash', 'rust', 'go',
23+
'json', 'yaml', 'html', 'css', 'c', 'cpp', 'java', 'ruby',
24+
'sql', 'xml', 'toml', 'diff', 'markdown', 'svelte',
25+
];
26+
1927
let highlighterPromise: Promise<HighlighterCore> | undefined;
2028
let resolvedParser: ParserFn | undefined;
2129

@@ -24,31 +32,10 @@ function getHighlighter(): Promise<HighlighterCore> {
2432
highlighterPromise = createHighlighterCore({
2533
engine: createJavaScriptRegexEngine(),
2634
themes: [
27-
import('shiki/themes/github-light'),
28-
import('shiki/themes/github-dark'),
29-
],
30-
langs: [
31-
import('shiki/langs/javascript'),
32-
import('shiki/langs/typescript'),
33-
import('shiki/langs/python'),
34-
import('shiki/langs/bash'),
35-
import('shiki/langs/rust'),
36-
import('shiki/langs/go'),
37-
import('shiki/langs/json'),
38-
import('shiki/langs/yaml'),
39-
import('shiki/langs/html'),
40-
import('shiki/langs/css'),
41-
import('shiki/langs/c'),
42-
import('shiki/langs/cpp'),
43-
import('shiki/langs/java'),
44-
import('shiki/langs/ruby'),
45-
import('shiki/langs/sql'),
46-
import('shiki/langs/xml'),
47-
import('shiki/langs/toml'),
48-
import('shiki/langs/diff'),
49-
import('shiki/langs/markdown'),
50-
import('shiki/langs/svelte'),
35+
bundledThemes['github-light'],
36+
bundledThemes['github-dark'],
5137
],
38+
langs: LANGS.map((id) => bundledLanguages[id]),
5239
});
5340
}
5441
return highlighterPromise;

0 commit comments

Comments
 (0)