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
BIN
View File
Binary file not shown.
+1 -2
View File
@@ -32,8 +32,7 @@
"server-only": "^0.0.1",
"shikiji": "^0.8.0",
"tailwind-merge": "^1.14.0",
"tailwind-shades": "^1.1.2",
"vscode-oniguruma": "^2.0.1"
"tailwind-shades": "^1.1.2"
},
"devDependencies": {
"@cloudflare/next-on-pages": "^1.7.3",
@@ -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');