From 6ebc071e13f68d3ba69fdc8761c10fa6a3f02753 Mon Sep 17 00:00:00 2001 From: jxom Date: Fri, 27 Sep 2024 12:12:28 +1000 Subject: [PATCH] fix: inline code highlighter --- .changeset/pretty-rice-heal.md | 5 +++++ src/vite/plugins/rehype/inline-shiki.ts | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 .changeset/pretty-rice-heal.md diff --git a/.changeset/pretty-rice-heal.md b/.changeset/pretty-rice-heal.md new file mode 100644 index 00000000..98a63382 --- /dev/null +++ b/.changeset/pretty-rice-heal.md @@ -0,0 +1,5 @@ +--- +"vocs": patch +--- + +Fixed inline code highlighter. diff --git a/src/vite/plugins/rehype/inline-shiki.ts b/src/vite/plugins/rehype/inline-shiki.ts index 6955b0cd..067497d8 100644 --- a/src/vite/plugins/rehype/inline-shiki.ts +++ b/src/vite/plugins/rehype/inline-shiki.ts @@ -1,7 +1,13 @@ import type { RehypeShikiCoreOptions } from '@shikijs/rehype/core' import type { Root } from 'hast' -import type { BuiltinLanguage, BuiltinTheme, Highlighter } from 'shiki' -import { bundledLanguages, createHighlighter } from 'shiki' +import type { + BuiltinLanguage, + BuiltinTheme, + BundledLanguage, + BundledTheme, + HighlighterGeneric, +} from 'shiki' +import { bundledLanguages, getSingletonHighlighter } from 'shiki' import type { LanguageInput } from 'shiki/core' import type { Plugin } from 'unified' import { visit } from 'unist-util-visit' @@ -17,7 +23,7 @@ export type RehypeInlineShikiOptions = RehypeShikiCoreOptions & { langs?: Array } -let promise: Promise +let promise: Promise> export const rehypeInlineShiki: Plugin<[RehypeInlineShikiOptions], Root> = function ( options = {} as any, @@ -29,7 +35,7 @@ export const rehypeInlineShiki: Plugin<[RehypeInlineShikiOptions], Root> = funct return async function (tree) { if (!promise) - promise = createHighlighter({ + promise = getSingletonHighlighter({ themes: themeNames, langs, })