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

Transforming the code #23

Open
arcanis opened this issue Mar 30, 2023 · 1 comment
Open

Transforming the code #23

arcanis opened this issue Mar 30, 2023 · 1 comment

Comments

@arcanis
Copy link

arcanis commented Mar 30, 2023

I'm trying to have Shiki Twoslash support in my mdx files, but I'm not sure it's currently possible.

My idea was to parse the original file as an AST, extract the code fences, send them to JavaScript for processing, and return them back before serializing it into mdx. However, the API here seems to only expose the compile function, which does both parsing and transformation. Would it be reasonable to split them in two operations?

@wooorm
Copy link
Owner

wooorm commented Apr 3, 2023

Hey! Depends a lot on how you want to do this.

a) If the output is dynamic, you have a framework, and so you can use a component. That component can turn code into a Shiki Twoslash thing. If you use React, RSC helps, such as with https://github.com/code-hike/bright
b) If the output is static, you can use normal client-side JavaScript. Such as like this: https://github.com/wooorm/starry-night#example-using-starry-night-on-the-client.
c) There could be a plugin system: #8. That would likely not support JavaScript though.

I am personally not a big fan of using Shiki with ASTs/VDOMs, because it generates strings of HTML. Which need to be parsed again. That kinda defeats the purpose of how all of unified, and this, is built! The entire benefit is that we go AST -> AST -> AST, which is fast!
Something like starry-night helps with that.

Would it be reasonable to split them in two operations?

You can get an AST with markdown-rs. It’s used in this project

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

No branches or pull requests

2 participants