Skip to content

Commit fc92a77

Browse files
committedNov 3, 2024·
fix: lazy load language definition on twoslash too
closes #4334
1 parent 11eb137 commit fc92a77

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed
 

‎src/node/markdown/plugins/highlight.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,14 @@ export async function highlight(
6565
codeTransformers: userTransformers = []
6666
} = options
6767

68-
const usingTwoslash = userTransformers.some(
69-
({ name }) => name === '@shikijs/vitepress-twoslash'
70-
)
71-
7268
const highlighter = await createHighlighter({
7369
themes:
7470
typeof theme === 'object' && 'light' in theme && 'dark' in theme
7571
? [theme.light, theme.dark]
7672
: [theme],
7773
langs: [
7874
...(options.languages || []),
79-
...Object.values(options.languageAlias || {}),
80-
81-
// patch for twoslash - https://github.com/vuejs/vitepress/issues/4334
82-
...(usingTwoslash
83-
? Object.keys((await import('shiki')).bundledLanguages)
84-
: [])
75+
...Object.values(options.languageAlias || {})
8576
],
8677
langAlias: options.languageAlias
8778
})
@@ -99,6 +90,14 @@ export async function highlight(
9990
return true
10091
}
10192

93+
// patch for twoslash - https://github.com/vuejs/vitepress/issues/4334
94+
const internal = highlighter.getInternalContext()
95+
const getLanguage = internal.getLanguage
96+
internal.getLanguage = (name) => {
97+
loadLanguage(name)
98+
return getLanguage.call(internal, name)
99+
}
100+
102101
await options?.shikiSetup?.(highlighter)
103102

104103
const transformers: ShikiTransformer[] = [

0 commit comments

Comments
 (0)
Please sign in to comment.