@@ -4,18 +4,28 @@ import { isTruthy } from '@antfu/utils'
4
4
import { fromAsyncCodeToHtml } from '@shikijs/markdown-it/async'
5
5
import { escapeVueInCode } from '../transform/utils'
6
6
7
- export default async function MarkdownItShiki ( { data : { config } , mode, utils } : ResolvedSlidevOptions ) {
8
- const transformers = [
9
- ...utils . shikiOptions . transformers || [ ] ,
10
- ( config . twoslash === true || config . twoslash === mode )
11
- && ( await import ( '@shikijs/vitepress-twoslash' ) ) . transformerTwoslash ( {
7
+ export default async function MarkdownItShiki ( { data : { config } , mode, utils : { shiki, shikiOptions } } : ResolvedSlidevOptions ) {
8
+ async function getTwoslashTransformer ( ) {
9
+ const [ , , { transformerTwoslash } ] = await Promise . all ( [
10
+ // trigger the shiki to load the langs
11
+ shiki . codeToHast ( '' , { lang : 'js' , ...shikiOptions } ) ,
12
+ shiki . codeToHast ( '' , { lang : 'ts' , ...shikiOptions } ) ,
13
+
14
+ import ( '@shikijs/vitepress-twoslash' ) ,
15
+ ] )
16
+ return transformerTwoslash ( {
12
17
explicitTrigger : true ,
13
18
twoslashOptions : {
14
19
handbookOptions : {
15
20
noErrorValidation : true ,
16
21
} ,
17
22
} ,
18
- } ) ,
23
+ } )
24
+ }
25
+
26
+ const transformers = [
27
+ ...shikiOptions . transformers || [ ] ,
28
+ ( config . twoslash === true || config . twoslash === mode ) && await getTwoslashTransformer ( ) ,
19
29
{
20
30
pre ( pre ) {
21
31
this . addClassToHast ( pre , 'slidev-code' )
@@ -27,8 +37,8 @@ export default async function MarkdownItShiki({ data: { config }, mode, utils }:
27
37
} satisfies ShikiTransformer ,
28
38
] . filter ( isTruthy ) as ShikiTransformer [ ]
29
39
30
- return fromAsyncCodeToHtml ( utils . shiki . codeToHtml , {
31
- ...utils . shikiOptions ,
40
+ return fromAsyncCodeToHtml ( shiki . codeToHtml , {
41
+ ...shikiOptions ,
32
42
transformers,
33
43
} )
34
44
}
0 commit comments