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

Migrate lexical-code from PrismJS to Shiki #6575

Open
ivailop7 opened this issue Aug 29, 2024 · 7 comments
Open

Migrate lexical-code from PrismJS to Shiki #6575

ivailop7 opened this issue Aug 29, 2024 · 7 comments
Labels
enhancement Improvement over existing feature

Comments

@ivailop7
Copy link
Collaborator

ivailop7 commented Aug 29, 2024

PrismJS appears to be no longer maintained and Shiki seems to be the closest maintained alternative for syntax highlighting. A number of people have suggested the migration and I agree it makes sense, primarily because PrismJS is not ESM and creates issues when used with certain server-side rendering frameworks.

@ivailop7 ivailop7 added the enhancement Improvement over existing feature label Aug 29, 2024
@etrepum
Copy link
Collaborator

etrepum commented Aug 29, 2024

I have looked into this a little bit, the downsides are:

  • Shiki is larger since it brings in a wasm build of the oniguruma regex engine (~500kb gzip I think) required to support the TextMate grammars that all of the syntax highlighting is defined with https://shiki.style/guide/bundles
  • It's designed more for ahead-of-time highlighting rather than as-you-type highlighting
  • It uses inline style rather than semantic classes

Probably not a deal-breaker for everyone but I assume that there are many people that would prefer the dead-end prismjs solution at <100kb

@ivailop7
Copy link
Collaborator Author

Not tied to the framework, but it appears everyone I've spoken to recently is switching to this one, short of Monaco and CodeMirror embeds. Size-wise - yes, 5x increase is significant. If there are other reasonable alternatives, I'm all ears.

@etrepum
Copy link
Collaborator

etrepum commented Aug 29, 2024

I didn't find anything better, which was disappointing. Maybe the ideal would be to properly divorce highlighting from the code node model so that either solution (or something bespoke, e.g. a custom treesitter based highlighter) could be used. For the most part it really is just a display concern, shouldn't need such tight coupling.

@etrepum
Copy link
Collaborator

etrepum commented Aug 30, 2024

Looks like https://github.com/wooorm/starry-night is a similar project to shiki but AST and class based

@etrepum
Copy link
Collaborator

etrepum commented Aug 31, 2024

Looks like the size concerns with Shiki are being addressed shikijs/shiki#761

@rockwotj
Copy link

Also - could the list of languages be made pluggable? If I want to support a different subset of prism langauges than the existing lexical-code package, I have to fork or patch the list of languages. Would be awesome if I could customize that without the fork/patch.

@etrepum
Copy link
Collaborator

etrepum commented Sep 23, 2024

Given that everything in prism is global you should be able to add languages by importing them before you import lexical code. Removing them is a bit trickier but you could configure your bundler to make some of them return an empty module or to eliminate those imports altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement over existing feature
Projects
None yet
Development

No branches or pull requests

3 participants