Skip to content

Commit

Permalink
Fix OCaml syntax highlighting (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
feihong authored Oct 16, 2024
1 parent b6086fd commit 01e6d0a
Show file tree
Hide file tree
Showing 2 changed files with 668 additions and 3 deletions.
17 changes: 14 additions & 3 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { readFileSync } from "fs";
import { join } from "path";
import { defineConfig } from "vitepress";
import { bundledLanguages } from "shiki";

// Modify bundledLanguages so it no longer contains the bundled OCaml grammar. This is needed because vitepress config
// doesn't allow you to override bundled grammars, see
// https://github.com/vuejs/vitepress/blob/78c4d3dda085f31912578237dfbe7b1c62f48859/src/node/markdown/plugins/highlight.ts#L65
delete bundledLanguages['ocaml'];

const toggleSyntaxScript = readFileSync(join(__dirname, './toggleSyntax.js'), 'utf8');

Expand All @@ -9,16 +15,21 @@ const reasonGrammar = JSON.parse(
readFileSync(join(__dirname, "./reasonml.tmLanguage.json"), "utf8")
);

// https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/dune.json
// From https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/dune.json
const duneGrammar = JSON.parse(
readFileSync(join(__dirname, "./dune.tmLanguage.json"), "utf8")
);

// https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/opam.json
// From https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/opam.json
const opamGrammar = JSON.parse(
readFileSync(join(__dirname, "./opam.tmLanguage.json"), "utf8")
);

// From https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/ocaml.json
const ocamlGrammar = JSON.parse(
readFileSync(join(__dirname, "./ocaml.tmLanguage.json"), "utf8")
);

const base = process.env.BASE || "unstable";

// https://vitepress.dev/reference/site-config
Expand All @@ -38,7 +49,7 @@ export default defineConfig({
hostname: `https://melange.re/${base}/`,
},
markdown: {
languages: [reasonGrammar, duneGrammar, opamGrammar],
languages: [duneGrammar, ocamlGrammar, opamGrammar, reasonGrammar],
},
themeConfig: {
outline: { level: [2, 3] },
Expand Down
Loading

0 comments on commit 01e6d0a

Please sign in to comment.