1
1
import { DocumentBlockCode , DocumentBlockCodeLine , DocumentInlineAnnotation } from '@gitbook/api' ;
2
2
import {
3
- loadWasm ,
3
+ createdBundledHighlighter ,
4
4
ThemedToken ,
5
- getHighlighter ,
6
5
createCssVariablesTheme ,
7
6
HighlighterGeneric ,
8
- bundledLanguages ,
9
- bundledThemes ,
10
- } from 'shiki' ;
7
+ } from 'shiki/core' ;
8
+ import { loadWasm , createOnigurumaEngine } from 'shiki/engine/oniguruma' ;
9
+ import { bundledLanguages } from 'shiki/langs ' ;
11
10
// @ts -ignore - onigWasm is a Wasm module
12
11
import onigWasm from 'shiki/onig.wasm?module' ;
13
12
14
13
import { asyncMutexFunction , singleton } from '@/lib/async' ;
15
14
import { getNodeText } from '@/lib/document' ;
16
15
import { trace } from '@/lib/tracing' ;
17
16
18
- import { DocumentContext } from '../DocumentView' ;
19
-
20
17
export type HighlightLine = {
21
18
highlighted : boolean ;
22
19
tokens : HighlightToken [ ] ;
@@ -299,6 +296,12 @@ function cleanupLine(line: string): string {
299
296
return line . replace ( / \r / g, '' ) ;
300
297
}
301
298
299
+ const createHighlighter = createdBundledHighlighter < any , any > ( {
300
+ langs : bundledLanguages ,
301
+ themes : { } ,
302
+ engine : ( ) => createOnigurumaEngine ( import ( 'shiki/wasm' ) ) ,
303
+ } ) ;
304
+
302
305
/**
303
306
* Load the highlighter, only once, and reuse it.
304
307
* It makes sure to handle concurrent calls.
@@ -312,7 +315,8 @@ const loadHighlighter = singleton(async () => {
312
315
// Otherwise for Vercel/Cloudflare, we need to load it ourselves.
313
316
await loadWasm ( ( obj ) => WebAssembly . instantiate ( onigWasm , obj ) ) ;
314
317
}
315
- const highlighter = await getHighlighter ( {
318
+
319
+ const highlighter = await createHighlighter ( {
316
320
themes : [ createCssVariablesTheme ( ) ] ,
317
321
langs : [ ] ,
318
322
} ) ;
@@ -322,7 +326,7 @@ const loadHighlighter = singleton(async () => {
322
326
323
327
const loadLanguagesMutex = asyncMutexFunction ( ) ;
324
328
async function loadHighlighterLanguage (
325
- highlighter : HighlighterGeneric < keyof typeof bundledLanguages , keyof typeof bundledThemes > ,
329
+ highlighter : HighlighterGeneric < any , any > ,
326
330
lang : keyof typeof bundledLanguages ,
327
331
) {
328
332
await loadLanguagesMutex . runBlocking ( async ( ) => {
0 commit comments