11import { DocumentBlockCode , DocumentBlockCodeLine , DocumentInlineAnnotation } from '@gitbook/api' ;
22import {
3- loadWasm ,
3+ createdBundledHighlighter ,
44 ThemedToken ,
5- getHighlighter ,
65 createCssVariablesTheme ,
76 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 ' ;
1110// @ts -ignore - onigWasm is a Wasm module
1211import onigWasm from 'shiki/onig.wasm?module' ;
1312
1413import { asyncMutexFunction , singleton } from '@/lib/async' ;
1514import { getNodeText } from '@/lib/document' ;
1615import { trace } from '@/lib/tracing' ;
1716
18- import { DocumentContext } from '../DocumentView' ;
19-
2017export type HighlightLine = {
2118 highlighted : boolean ;
2219 tokens : HighlightToken [ ] ;
@@ -299,6 +296,12 @@ function cleanupLine(line: string): string {
299296 return line . replace ( / \r / g, '' ) ;
300297}
301298
299+ const createHighlighter = createdBundledHighlighter < any , any > ( {
300+ langs : bundledLanguages ,
301+ themes : { } ,
302+ engine : ( ) => createOnigurumaEngine ( import ( 'shiki/wasm' ) ) ,
303+ } ) ;
304+
302305/**
303306 * Load the highlighter, only once, and reuse it.
304307 * It makes sure to handle concurrent calls.
@@ -312,7 +315,8 @@ const loadHighlighter = singleton(async () => {
312315 // Otherwise for Vercel/Cloudflare, we need to load it ourselves.
313316 await loadWasm ( ( obj ) => WebAssembly . instantiate ( onigWasm , obj ) ) ;
314317 }
315- const highlighter = await getHighlighter ( {
318+
319+ const highlighter = await createHighlighter ( {
316320 themes : [ createCssVariablesTheme ( ) ] ,
317321 langs : [ ] ,
318322 } ) ;
@@ -322,7 +326,7 @@ const loadHighlighter = singleton(async () => {
322326
323327const loadLanguagesMutex = asyncMutexFunction ( ) ;
324328async function loadHighlighterLanguage (
325- highlighter : HighlighterGeneric < keyof typeof bundledLanguages , keyof typeof bundledThemes > ,
329+ highlighter : HighlighterGeneric < any , any > ,
326330 lang : keyof typeof bundledLanguages ,
327331) {
328332 await loadLanguagesMutex . runBlocking ( async ( ) => {
0 commit comments