From 7da9b28681c298c560899d597e712e240a5d66b7 Mon Sep 17 00:00:00 2001 From: ashour Date: Fri, 28 Apr 2023 12:35:35 +0000 Subject: [PATCH] docs: guide for adding custom grammars for syntax highlighting --- docs/content/4.api/3.configuration.md | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/content/4.api/3.configuration.md b/docs/content/4.api/3.configuration.md index a119f1954..efc24a46e 100644 --- a/docs/content/4.api/3.configuration.md +++ b/docs/content/4.api/3.configuration.md @@ -317,6 +317,36 @@ export default defineNuxtConfig({ }) ``` +If you wish to add highlighting for an unsupported language, you can do so by loading the grammar file for the language. + +```ts +import { readFileSync } from 'fs' + +export default defineNuxtConfig({ + content: { + highlight: { + preload: [ + { + id: 'gdscript', + scopeName: 'source.gdscript', + aliases: ['gdscript', 'gd'], // Use to mark code blocks in Markdown + grammar: JSON.parse( + readFileSync( + // Place the language grammar file somewhere in your project + './shiki/languages/gdscript.tmLanguage.json' + ).toString() + ), + }, + ], + }, + }, +}) + +``` + +Read more about adding languages in the [Shiki documentation](https://github.com/shikijs/shiki/blob/main/docs/languages.md#adding-grammar). + + ## `yaml` - Type: `false | Object`{lang=ts}