Skip to content

Add mdx-react generator #6

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

Open
ovflowd opened this issue May 30, 2024 · 3 comments
Open

Add mdx-react generator #6

ovflowd opened this issue May 30, 2024 · 3 comments

Comments

@ovflowd
Copy link
Member

ovflowd commented May 30, 2024

Following up the extraction of the MDX parser into a dedicated generator that converts the plain Markdown into an MDX template, we should compile it into React.

This effectively introduces the react and mdx dependencies into the project. Proper ESLint and Prettier configuration for React and JSX should be added. This can be done by importing compatible rules from the Node.js Website repository.

This generator should pretty much receive the content transformed into an MDX template from the mdx generator; the MDX generator returns a VFile, with the caveat that the main content is now replaced with the MDX template, but both the metadata and file metadata remain in the VFile.

Then the mdx-react receives that VFile and pretty much compiles the MDX and evaluates it into JSX by running it with MDX https://mdxjs.com/packages/mdx/#evaluatefile-options

Hence, this generator's output is again a VFile containing the source content and the generated JSX function within the data attribute.

Note that the generated React is simply the content of the page, not the whole page (navigation, header, etc.). Think of this as the inner content of a blog post.

@avivkeller
Copy link
Member

avivkeller commented Mar 23, 2025

This generator should pretty much receive the content transformed into an MDX template from the mdx generator; the MDX generator returns a VFile, with the caveat that the main content is now replaced with the MDX template, but both the metadata and file metadata remain in the VFile.

Then the mdx-react receives that VFile and pretty much compiles the MDX and evaluates it into JSX by running it with MDX mdxjs.com/packages/mdx#evaluatefile-options

Could you share a bit more about how you see the mdx generator working? I’m trying to wrap my head around the step between Markdown and the final compiled JSX. Why does the content need to be turned "into an MDX template" first? Wouldn't that just be part of converting it to JSX in the mdx-react generator?

Specifically, when you say " the main content is now replaced with the MDX template", the main content is markdown, which is already basically mdx?

@ovflowd
Copy link
Member Author

ovflowd commented Mar 23, 2025

Could you share a bit more about how you see the mdx generator working? I’m trying to wrap my head around the step between Markdown and the final compiled JSX. Why does the content need to be turned "into an MDX template" first? Wouldn't that just be part of converting it to JSX in the mdx-react generator?

So, pretty much the base generator transforms the raw Markdown content into Nodes, these Nodes also have the raw content (Markdown there), then we have the legacy-html generator for example, that transforms into HTML pages.

The mdx generator in question is just a "jsx" generator, or "md-jsx" or "mdx-jsx" (we don't really need any MDX parser at the moment, because unified already parsed it). But the point is that it is grabbing the source "mdx/md" into -> "jsx" which is pretty much "grabbing the md content (and metadata) and filling it inside JSX layouts.

This parser will contains also all the JSX-specific components.

  • package.json - add @node-core/ui-components
  • generators/md-jsx (or mdx-jsx or just jsx)
    • components/ (components specific to API docs)
    • layouts/ (layouts specific to API docs)

Then we have the "react-web" generator or "jsx-html" (whatever we name it) (probably replacing #7) (idk?)

When I wrote those generator ideas... it was a long time ago 😅

But the final generator, would have HTML templates and have the bundles being bundled into it (either inline or what not) -- or whatever we decide to use to build the final app. It could be Vite, or what not :)

@avivkeller
Copy link
Member

Got it! Thanks for elaborating. I think I got confused between mdx, mdx-react, and react-web, thanks for clarifying!

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

No branches or pull requests

2 participants