wooorm / xdm

Just a *really* good MDX compiler. No runtime. With esbuild, Rollup, and webpack plugins
http://wooorm.com/xdm/
MIT License
595 stars 18 forks source link

How to get tree from compile ? #107

Closed dmitryshelomanov closed 2 years ago

dmitryshelomanov commented 2 years ago

I need compile's tree and render it in react I want to try crate editor with tree from server api (I need light weight render without evulate and etc)

wooorm commented 2 years ago

Impossible

dmitryshelomanov commented 2 years ago

@wooorm

why ? I have tree and can traverse it

traverse(tree, components)

I thought such libraries already exist

wooorm commented 2 years ago

Yes, you can do such things. Your question is vague. This project doesn’t do that. This project compiles MDX -> JS.

ChristianMurphy commented 2 years ago

I need compile's tree

If you are looking for direct access to the abstract syntax tree https://github.com/mdx-js/mdx/tree/main/packages/remark-mdx can be used

render it in react

If your goal is to render it, consider directly rendering it fully serverside or rendering it fully client side. Trying a hybrid client-server approach, sending the AST between them, without a reason, probably isn't a good idea.

You may want to look into something like https://wooorm.com/server-components-mdx-demo as an alternative way to have a static page, with a few dynamic elements.

I want to try crate editor with tree from server api

It's unclear what you mean by this. Editors generally run fully client side.

(I need light weight render without evulate and etc)

MDX/XDM can render server side, though the round trip time likely wouldn't be ideal for an editor experience.