Skip to content

Commit 7da9b28

Browse files
authored
docs: guide for adding custom grammars for syntax highlighting
1 parent 82ccc1f commit 7da9b28

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/content/4.api/3.configuration.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,36 @@ export default defineNuxtConfig({
317317
})
318318
```
319319

320+
If you wish to add highlighting for an unsupported language, you can do so by loading the grammar file for the language.
321+
322+
```ts
323+
import { readFileSync } from 'fs'
324+
325+
export default defineNuxtConfig({
326+
content: {
327+
highlight: {
328+
preload: [
329+
{
330+
id: 'gdscript',
331+
scopeName: 'source.gdscript',
332+
aliases: ['gdscript', 'gd'], // Use to mark code blocks in Markdown
333+
grammar: JSON.parse(
334+
readFileSync(
335+
// Place the language grammar file somewhere in your project
336+
'./shiki/languages/gdscript.tmLanguage.json'
337+
).toString()
338+
),
339+
},
340+
],
341+
},
342+
},
343+
})
344+
345+
```
346+
347+
Read more about adding languages in the [Shiki documentation](https://github.com/shikijs/shiki/blob/main/docs/languages.md#adding-grammar).
348+
349+
320350
## `yaml`
321351

322352
- Type: `false | Object`{lang=ts}

0 commit comments

Comments
 (0)