Skip to content

Commit 01e6d0a

Browse files
authored
Fix OCaml syntax highlighting (#197)
1 parent b6086fd commit 01e6d0a

File tree

2 files changed

+668
-3
lines changed

2 files changed

+668
-3
lines changed

docs/.vitepress/config.mts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { readFileSync } from "fs";
22
import { join } from "path";
33
import { 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

511
const 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
1319
const 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
1824
const 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+
2233
const base = process.env.BASE || "unstable";
2334

2435
// https://vitepress.dev/reference/site-config
@@ -38,7 +49,7 @@ export default defineConfig({
3849
hostname: `https://melange.re/${base}/`,
3950
},
4051
markdown: {
41-
languages: [reasonGrammar, duneGrammar, opamGrammar],
52+
languages: [duneGrammar, ocamlGrammar, opamGrammar, reasonGrammar],
4253
},
4354
themeConfig: {
4455
outline: { level: [2, 3] },

0 commit comments

Comments
 (0)