Skip to content

Commit c4f030d

Browse files
committedJul 2, 2024··
fix(rehype): default export use shared highlighter instance, fix #714
1 parent 4c1de34 commit c4f030d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed
 

‎docs/packages/rehype.md

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const file = await unified()
3838
.process(await fs.readFile('./input.md'))
3939
```
4040

41+
The default export of `@shikijs/rehype` uses a shared instance of `shiki` from `getSingletonHighlighter`, which will persist across processes. If you want full control over the highlighter lifecycle, use [Fine-grained Bundle `@shikijs/rehype/core`](#fine-grained-bundle) instead.
42+
4143
## Fine-grained Bundle
4244

4345
By default, the full bundle of `shiki` will be imported. If you are using a [fine-grained bundle](/guide/install#fine-grained-bundle), you can import `rehypeShikiFromHighlighter` from `@shikijs/rehype/core` and pass your own highlighter:

‎packages/rehype/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/// <reference types="mdast-util-to-hast" />
2+
23
import type { LanguageInput } from 'shiki/core'
34
import type { BuiltinLanguage, BuiltinTheme } from 'shiki'
4-
import { bundledLanguages, createHighlighter } from 'shiki'
5+
import { bundledLanguages, getSingletonHighlighter } from 'shiki'
56
import type { Plugin } from 'unified'
67
import type { Root } from 'hast'
78
import rehypeShikiFromHighlighter from './core'
@@ -27,7 +28,7 @@ const rehypeShiki: Plugin<[RehypeShikiOptions], Root> = function (
2728

2829
return async (tree) => {
2930
if (!getHandler) {
30-
getHandler = createHighlighter({
31+
getHandler = getSingletonHighlighter({
3132
themes: themeNames,
3233
langs,
3334
})

0 commit comments

Comments
 (0)
Please sign in to comment.