Skip to content

Starlight

Syntax highlighting of custom languages

To add syntax highlighting for a language that is not supported by Shiki by default, follow these instructions.

Example: Odin

  • Find a suitable textmate json object file, such as this.
    • save the file to e.g. src/syntax/odin.tmLanguage.json
  • Edit astro.config.js
    • Add:
1
integrations: [starlight({
2
title: 'jmn docs',
3
expressiveCode: {
4
plugins: [pluginLineNumbers()],
5
shiki: {
6
langs: [
7
JSON.parse(fs.readFileSync('./src/syntax/odin.tmLanguage.json', 'utf-8'))
8
]
9
}
10
},
11
...

Example Odin code block

1
package main
2
3
import "core:fmt"
4
5
main :: proc() {
6
fmt.println("Hellope, World!");
7
}

References