jupyter-book / mystmd

Command line tools for working with MyST Markdown.
https://mystmd.org/guide
MIT License
219 stars 65 forks source link

Investigate the use of shiki as the library for syntax highlighting #1683

Open Nova38 opened 3 days ago

Nova38 commented 3 days ago

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

agoose77 commented 3 days ago

I recall seeing this mentioned somewhere ... turns out it was you! https://discord.com/channels/1083088970059096114/1083088970059096117/1295937103846314004

Nova38 commented 3 days ago

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)

choldgraf commented 3 days ago

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!

Nova38 commented 3 days ago

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!

rowanc1 commented 3 days ago

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

Nova38 commented 3 days ago

Here are some of my initial thoughts

Nova38 commented 3 days ago

Is there a way to override an existing component and inject different project specific component?

stevejpurves commented 2 days ago

@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.

Nova38 commented 1 day ago

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?