-
Notifications
You must be signed in to change notification settings - Fork 28
Add support for custom Shiki languages #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Modelled after the custom theme registration. I don't have an easy way to test this but i believe it _should_ just work
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds an API to register and use custom Shiki languages (dynamic loaders + filename/extension mapping) so syntax highlighting can work for non-bundled grammars.
Changes:
- Introduces
registerCustomLanguageand a custom language registry used by language resolution. - Extends filename/extension-to-language detection to support custom mappings.
- Updates public types/exports and docs to reflect custom language support.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/diffs/src/utils/setLanguageOverride.ts | Updates typing for language overrides (now via overloads). |
| packages/diffs/src/utils/getFiletypeFromFileName.ts | Adds a custom mapping Map and checks it during language inference. |
| packages/diffs/src/types.ts | Expands SupportedLanguages to allow custom string language IDs. |
| packages/diffs/src/index.ts | Exports the new registerCustomLanguage API. |
| packages/diffs/src/highlighter/languages/resolveLanguage.ts | Resolves languages from either bundled Shiki loaders or registered custom loaders. |
| packages/diffs/src/highlighter/languages/registerCustomLanguage.ts | New API to register custom language loaders and optional extension/filename mappings. |
| packages/diffs/src/highlighter/languages/constants.ts | Adds storage for registered custom language loaders. |
| apps/docs/app/docs/page.tsx | Wires the new utility example into the docs page rendering/preloading. |
| apps/docs/app/docs/Utilities/content.mdx | Adds documentation section for registerCustomLanguage. |
| apps/docs/app/docs/Utilities/constants.ts | Adds a runnable docs helper snippet demonstrating registerCustomLanguage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
A quick side quest for #301
Essentially this re-creates a language registry for custom shiki grammars. I haven't been really tested this yet though, but I think it should just work.
Basically I created a registration API like custom theme where you provide a language, a loader and some file extensions/filenames to map the language to. Then just rely on automatic language detection or utilize language overrides:
Fixes #301