Skip to content

Conversation

@amadeus
Copy link
Member

@amadeus amadeus commented Jan 29, 2026

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:

registerCustomLanguage(
  'my-lang', 
  () => import('./my-lang.tmLanguage.json'),
  ['mylang']
);

// And later on you would just do something like

<File
  file={{
    name: 'example.mylang',
    contents: '' // etc
  }}
/>

// or
<File
  file={{
    name: 'example',
    contents: '', // etc
    lang: 'my-lang'
  }}
/>

Fixes #301

Modelled after the custom theme registration.  I don't have an easy way
to test this but i believe it _should_ just work
@vercel
Copy link

vercel bot commented Jan 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
pierrejs-diff-demo Ready Ready Preview Jan 29, 2026 7:34am
pierrejs-docs Ready Ready Preview Jan 29, 2026 7:34am
pierrejs-solid-diff-demo Ready Ready Preview Jan 29, 2026 7:34am

Request Review

Copy link

Copilot AI left a 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 registerCustomLanguage and 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: custom shiki grammars

2 participants