Skip to content

Commit

Permalink
fix: inline code highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Sep 27, 2024
1 parent 13db87c commit 6ebc071
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-rice-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vocs": patch
---

Fixed inline code highlighter.
14 changes: 10 additions & 4 deletions src/vite/plugins/rehype/inline-shiki.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -17,7 +23,7 @@ export type RehypeInlineShikiOptions = RehypeShikiCoreOptions & {
langs?: Array<LanguageInput | BuiltinLanguage>
}

let promise: Promise<Highlighter>
let promise: Promise<HighlighterGeneric<BundledLanguage, BundledTheme>>

export const rehypeInlineShiki: Plugin<[RehypeInlineShikiOptions], Root> = function (
options = {} as any,
Expand All @@ -29,7 +35,7 @@ export const rehypeInlineShiki: Plugin<[RehypeInlineShikiOptions], Root> = funct

return async function (tree) {
if (!promise)
promise = createHighlighter({
promise = getSingletonHighlighter({
themes: themeNames,
langs,
})
Expand Down

0 comments on commit 6ebc071

Please sign in to comment.