Open Nova38 opened 3 days ago
I recall seeing this mentioned somewhere ... turns out it was you! https://discord.com/channels/1083088970059096114/1083088970059096117/1295937103846314004
Yep! I finally have some free time to work on some contributions to a few projects, so I wanted to open the floor to see if this is something that would be desired.
I recall seeing this mentioned somewhere ... turns out it was you! https://discord.com/channels/1083088970059096114/1083088970059096117/1295937103846314004
I also forgot to add that it is really easy to add custom languages to shiki as the consumer of the library. I think that might be useful if someone wanted to have syntax highlight for a custom languages (such as if it was a book about language design/compilers and they made up a simple language) (See https://shiki.style/guide/load-lang)
Thanks for this idea @Nova38 ! I wanted to share a few quick questions to help us triage this idea a bit. I promise they're not coming from a place of skepticism - just trying to understand cost/benefit!
No worries, I completely understand. Those are excellent questions! I will work on writing up those and should have them in a short bit.
To aid the comparison is there a specific package that handles the code directive/syntax highlighting directive? I used the GitHub search to find where https://github.com/react-syntax-highlighter/react-syntax-highlighter was being used, but I am unfamiliar with the codebase and want to make sure I am comparing it to the correct spot. If you know of the top of your head could you point me in the right direction please? If not don't worry about it I'll just keep going through it.
Thanks!
The syntax highlighter is used in the myst-theme package here:
https://github.com/jupyter-book/myst-theme/blob/main/packages/myst-to-react/src/code.tsx#L106
Here are some of my initial thoughts
What's the benefit of using this over the current system we use for syntax highlighting? (in functionality, maintenance cost, long-term outlook, UX, etc?)
An example of what is possible, here is it intigrated with typescripts Shiki Twoslash: Static Code Samples for JS Projects - https://shikijs.github.io/twoslash/
The UX of adding new transfomations is a lot more consise
Functionality:
import { codeToHtml } from 'shiki'
const html = await codeToHtml(code, {
theme: 'vitesse-light',
lang: 'ts',
decorations: [
{
// line and character are 0-indexed
start: { line: 1, character: 0 },
end: { line: 1, character: 11 },
properties: { class: 'highlighted-word' }
}
]
It has some built in transformations that could improve code readability such as the @shikijs/colorized-brackets | Shiki - https://shiki.style/packages/colorized-brackets and Shiki Magic Move Demo - https://shiki-magic-move.netlify.app/ Usng
Longterm outlook
Maintenance cost
// [!code highlight]
How much work would it be to implement and then maintain this?
Why should this be the most important thing to use maintainer time implementing/reviewing/etc?
Is there a way to override an existing component and inject different project specific component?
@Nova38 no not on the renderer/theme/react side of things, this is part of the plugin framework that has yet to be fleshed out.
+1 for shikijs
being pure ESM though. We've had to wrangle with react-syntax-highlighter
at times due to the way it is packaged, trying to be a cjs/esm distribution.
I am not sure that I entirely follow the question. Are you wanting how it by itself can be adapted into a plugin itself, how it could fit in by themselves exposing parts of it that other plugins could then be able to expand on it and add new features to the code blocks, or is it something else?
Proposal
Use shiki, https://shiki.style/, as the syntax highlighting library for mystmd. It uses the same syntax highlighting engine as vscode and has very good tooling.
Additional notes
It is used in a lot of open source projects