Skip to content

Commit

Permalink
chore: update shiki usage
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jun 25, 2024
1 parent c4a9a14 commit 8408733
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/slidev/node/virtual/shiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export const templateShiki: VirtualModuleTemplate = {

const lines: string[] = []
lines.push(
`import { getHighlighterCore } from "${await resolveImportUrl('shiki/core')}"`,
`import { createHighlighterCore } from "${await resolveImportUrl('shiki/core')}"`,
`export { shikiToMonaco } from "${await resolveImportUrl('@shikijs/monaco')}"`,

`export const languages = ${JSON.stringify(langNames)}`,
`export const themes = ${JSON.stringify(themeOptionsNames.themes || themeOptionsNames.theme)}`,

'export const shiki = getHighlighterCore({',
'export const shiki = createHighlighterCore({',
` themes: [${themesInit.join(',')}],`,
` langs: [${langsInit.join(',')}],`,
` loadWasm: import('${await resolveImportUrl('shiki/wasm')}'),`,
Expand Down
6 changes: 3 additions & 3 deletions packages/slidev/node/vite/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ export async function createMarkdownPlugin(
async function createMarkdownItShiki(clientRoot: string, roots: string[], config: SlidevConfig, mode: string) {
const [
shikiOptions,
{ getHighlighter, bundledLanguages },
{ createHighlighter, bundledLanguages },
markdownItShiki,
transformerTwoslash,
] = await Promise.all([
loadShikiSetups(clientRoot, roots),
import('shiki').then(({ getHighlighter, bundledLanguages }) => ({ bundledLanguages, getHighlighter })),
import('shiki').then(({ createHighlighter, bundledLanguages }) => ({ bundledLanguages, createHighlighter })),
import('@shikijs/markdown-it/core').then(({ fromHighlighter }) => fromHighlighter),
import('@shikijs/vitepress-twoslash').then(({ transformerTwoslash }) => transformerTwoslash),
] as const)

const shiki = await getHighlighter({
const shiki = await createHighlighter({
...shikiOptions as any,
langs: shikiOptions.langs ?? Object.keys(bundledLanguages),
themes: 'themes' in shikiOptions ? Object.values(shikiOptions.themes) : [shikiOptions.theme],
Expand Down
6 changes: 3 additions & 3 deletions test/transform-magic-move.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, it } from 'vitest'
import { getHighlighter } from 'shiki'
import { createHighlighter } from 'shiki'
import { transformMagicMove } from '../packages/slidev/node/syntax/transform'
import { createTransformContext } from './_tutils'

Expand All @@ -21,7 +21,7 @@ let message = 'Hello, Slidev!'
Some text after
`
const shiki = await getHighlighter({
const shiki = await createHighlighter({
themes: ['nord'],
langs: ['typescript'],
})
Expand Down Expand Up @@ -67,7 +67,7 @@ console.log('Hello, Angular #2!')
Some text after
`
const shiki = await getHighlighter({
const shiki = await createHighlighter({
themes: ['nord'],
langs: ['angular-ts'],
})
Expand Down

0 comments on commit 8408733

Please sign in to comment.