shikijs / twoslash

You take some Shiki, add a hint of TypeScript compiler, and 🎉 incredible static code samples
https://shikijs.github.io/twoslash/
MIT License
1.04k stars 50 forks source link

[Docusaurus] entrypoint to add custom textmate grammar ? #190

Open Baccata opened 10 months ago

Baccata commented 10 months ago

Hello everyone.

I'm looking for a way to configure the docusaurus plugin with a custom textmate grammar to get highlighting for languages that aren't supported out-of-the-box by Shiki.

Could anyone offer some guidance as to what would be the most straightforward way to achieve this ?

lachieh commented 9 months ago

You should be able to add the custom grammar in the options at the same place you define which themes to use. Note that you have to extend the existing languages by importing them from the 'shiki' package. As an example, this is how I've handled it:

import { BUNDLED_LANGUAGES } from 'shiki';

// see docs for where to put options:
{
  themes: ['github-light', 'github-dark'],
  langs: [
    ...BUNDLED_LANGUAGES,
    {
      id: 'wit',
      scopeName: 'source.wit',
      path: path.resolve('./languages/wit.tmLanguage.json'),
      aliases: ['wit'],
    },
  ],
}