Skip to content

Commit

Permalink
fix: lazy load language definition on twoslash too
Browse files Browse the repository at this point in the history
closes #4334
  • Loading branch information
brc-dd committed Nov 3, 2024
1 parent 11eb137 commit fc92a77
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/node/markdown/plugins/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,14 @@ export async function highlight(
codeTransformers: userTransformers = []
} = options

const usingTwoslash = userTransformers.some(
({ name }) => name === '@shikijs/vitepress-twoslash'
)

const highlighter = await createHighlighter({
themes:
typeof theme === 'object' && 'light' in theme && 'dark' in theme
? [theme.light, theme.dark]
: [theme],
langs: [
...(options.languages || []),
...Object.values(options.languageAlias || {}),

// patch for twoslash - https://github.com/vuejs/vitepress/issues/4334
...(usingTwoslash
? Object.keys((await import('shiki')).bundledLanguages)
: [])
...Object.values(options.languageAlias || {})
],
langAlias: options.languageAlias
})
Expand All @@ -99,6 +90,14 @@ export async function highlight(
return true
}

// patch for twoslash - https://github.com/vuejs/vitepress/issues/4334
const internal = highlighter.getInternalContext()
const getLanguage = internal.getLanguage
internal.getLanguage = (name) => {
loadLanguage(name)
return getLanguage.call(internal, name)
}

await options?.shikiSetup?.(highlighter)

const transformers: ShikiTransformer[] = [
Expand Down

0 comments on commit fc92a77

Please sign in to comment.