11import { readFileSync } from "fs" ;
22import { join } from "path" ;
33import { defineConfig } from "vitepress" ;
4+ import { bundledLanguages } from "shiki" ;
5+
6+ // Modify bundledLanguages so it no longer contains the bundled OCaml grammar. This is needed because vitepress config
7+ // doesn't allow you to override bundled grammars, see
8+ // https://github.com/vuejs/vitepress/blob/78c4d3dda085f31912578237dfbe7b1c62f48859/src/node/markdown/plugins/highlight.ts#L65
9+ delete bundledLanguages [ 'ocaml' ] ;
410
511const toggleSyntaxScript = readFileSync ( join ( __dirname , './toggleSyntax.js' ) , 'utf8' ) ;
612
@@ -9,16 +15,21 @@ const reasonGrammar = JSON.parse(
915 readFileSync ( join ( __dirname , "./reasonml.tmLanguage.json" ) , "utf8" )
1016) ;
1117
12- // https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/dune.json
18+ // From https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/dune.json
1319const duneGrammar = JSON . parse (
1420 readFileSync ( join ( __dirname , "./dune.tmLanguage.json" ) , "utf8" )
1521) ;
1622
17- // https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/opam.json
23+ // From https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/opam.json
1824const opamGrammar = JSON . parse (
1925 readFileSync ( join ( __dirname , "./opam.tmLanguage.json" ) , "utf8" )
2026) ;
2127
28+ // From https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/ocaml.json
29+ const ocamlGrammar = JSON . parse (
30+ readFileSync ( join ( __dirname , "./ocaml.tmLanguage.json" ) , "utf8" )
31+ ) ;
32+
2233const base = process . env . BASE || "unstable" ;
2334
2435// https://vitepress.dev/reference/site-config
@@ -38,7 +49,10 @@ export default defineConfig({
3849 hostname : `https://melange.re/${ base } /` ,
3950 } ,
4051 markdown : {
41- languages : [ reasonGrammar , duneGrammar , opamGrammar ] ,
52+ languages : [ duneGrammar , ocamlGrammar , opamGrammar , reasonGrammar ] ,
53+ shikiSetup : highlighter => {
54+ highlighter . loadLanguage ( ocamlGrammar ) ;
55+ }
4256 } ,
4357 themeConfig : {
4458 outline : { level : [ 2 , 3 ] } ,
0 commit comments