Skip to content
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

Bracket pair colorization #303

Closed
theoludwig opened this issue Feb 22, 2022 · 10 comments · Fixed by #831
Closed

Bracket pair colorization #303

theoludwig opened this issue Feb 22, 2022 · 10 comments · Fixed by #831

Comments

@theoludwig
Copy link

Hey! 👋

Thanks for this awesome package, I can finally use VSCode default Dark+ theme syntax highlighting on my blog. 😄
I'm wondering if Bracket pair colorization could be added to Shiki? It has been added to VSCode natively since v1.60 with settings.json: "editor.bracketPairColorization.enabled": true.

With VSCode:

image

With Shiki

image

@muenzpraeger
Copy link
Collaborator

That should be in now with 0.12.0.

@theoludwig
Copy link
Author

That should be in now with 0.12.0.

How do you enable it? It seems like it is not enabled by default? I updated to [email protected], and there is still no bracket pair colorization. @muenzpraeger

@muenzpraeger
Copy link
Collaborator

@divlo VSCode itself has built-in bracket-pair colorization (based on runtime inspection of the code). If that should be replicated in a non-IDE situation like here with Shiki the tmLangauge definition as well as the the used theme have to provide that information.

@octref
Copy link
Collaborator

octref commented Jan 26, 2023

This requires extracting the VS Code bracket pair colorization logic out and bringing it to shiki. I don't quite have the bandwidth to do it right now.

@MichaelMakesGames
Copy link
Contributor

MichaelMakesGames commented Aug 4, 2024

Hey all, I just published a plugin for Shiki that can do this: GitHub / JSR

It is used as a tranformer, like this:

import shikiColorizedBrackets from '@michael-makes/shiki-colorized-brackets';
import { codeToHtml } from 'shiki';

const html = await codeToHtml('let values: number[] = [];', {
  lang: 'ts',
  theme: 'dark-plus',
  transformers: [shikiColorizedBrackets()],
});

When using shiki + the transformer on the above snippet, this is the output:
shiki-colorized-brackets-example

I've tested lots of languages and situations, but I'm sure there's some edge-cases I've missed, so feedback is appreciated.

PS: if the Shiki maintainers are interested, we could discuss making this an official plugin ;)

@antfu
Copy link
Member

antfu commented Aug 12, 2024

Awesome @MichaelMakesGames! I'd love to have it as an official plugin :) Do you want to draft a PR first? Thank you

@MichaelMakesGames
Copy link
Contributor

MichaelMakesGames commented Aug 12, 2024

@antfu sure thing! But can you take a look at #736 first? The plug-in needs some info from includeExplanation, and #736 could improve the slowdown from ~5x to ~2x. I'd be happy to submit a PR for that issue too

@MichaelMakesGames
Copy link
Contributor

@antfu this should be part of the @shiki/transformers package, or a separate package? It seems a bit larger/more complicated than the transformers in @shiki/transformers, but not nearly as complicated as @shiki/twoslash

I might try to get a couple more edge-cases handled before submitting a PR (bracket highlighting in JSDoc comments, and support for multi-character brackets such as {{ in Angular templates)

@antfu
Copy link
Member

antfu commented Aug 16, 2024

I would up to have it as a separate package :)

@MichaelMakesGames
Copy link
Contributor

Delayed but not forgotten :)

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

Successfully merging a pull request may close this issue.

5 participants