Fix code highlighting in Cloudflare (#27)

* Try calling WebAssembly.instantiate directly

* Load from shikiji/onig.wasm instead
This commit is contained in:
Samy Pessé
2023-12-11 13:43:30 +01:00
committed by GitHub
parent e880bce80b
commit 860bc02aa8
3 changed files with 3 additions and 4 deletions
@@ -1,7 +1,7 @@
import { DocumentBlockCode, DocumentBlockCodeLine, DocumentInlineAnnotation } from '@gitbook/api';
import { getHighlighter, loadWasm, bundledLanguages, Highlighter, ThemedToken } from 'shikiji';
// @ts-ignore - onigWasm is a Wasm module
import onigWasm from 'vscode-oniguruma/release/onig.wasm?module';
import onigWasm from 'shikiji/onig.wasm?module';
import { getNodeText } from '@/lib/document';
@@ -301,7 +301,7 @@ async function loadHighlighter() {
// loads it on its own.
//
// Otherwise for Vercel/Cloudflare, we need to load it ourselves.
await loadWasm(onigWasm);
await loadWasm(obj => WebAssembly.instantiate(onigWasm, obj))
}
const instance = await getHighlighter();
await instance.loadTheme('css-variables');