-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Creating new node types from inline JSX #13
Comments
That's very possible, you can extend mdast with any nodes you like. Inside the remark ecosystem, however, you may not fare too well: unknown nodes are ignored or thrown about when found, depending on the plugin. You'll also run in the compiler (remark-stringify, used in remark), which will not know what to do with them. If it looks like HTML, and quacks like HTML, why not use the 'html' type? Note that, if you use your own compiler (e.g., remark-react has their own), you can always do funky stuff in that when compiling to a virtual dom. Finally, could you expand some more on how you're planning to handle the new nodes? It's an interesting problem and I'd like to help. |
Oh cool! Perfect. So for the next version of Gatsby I'm building a new data layer based on GraphQL. GraphQL is cool in lots of ways but one big reason is it let's the client (in this case React.js components) tell the server (Gatsby) what data it wants. So the server can offer data in all sorts of ways and the client can pick and choose from the offerings. So for markdown, I want Gatsby to expose markdown in every possible way that a client could want. So the obvious way for a client to query for markdown data is for the compiled HTML string. But for maximum flexibility I want to give people the option to query the markdown AST directly and build React components directly from the raw markdown AST data. They could specify which components they want to handle lists, paragraphs, headers, etc. This is why it'd be ideal to parse JSX and add the parsed nodes alongside the markdown nodes so the user could just match the Make sense? Seem like a sensible plan? |
Hope that answered the issue. If not, either use Gitter, or create a new issue! |
I finally figured out how to get HTML in markdown, properly: https://github.com/wooorm/rehype-raw, which may be useful! |
@wooorm is there an example of extending node type? For example I'd like to support something like this block:
Is it parsed as paragraph by default? |
I'm working on a new version of my React static site generator Gatsby and want to natively support embedding JSX (for React components) inside Markdown e.g.
The user when building the site would then specify what is
Quiz
.I see from the Markdown parser demo that you put raw HTML into its own node type. Would it be possible to write a plugin which instead parses the HTML w/ a JSX parser and creates a node type of
Quiz
along with its attributes and any children? If so, I'd really appreciate some pointers!! This is something I really want and a number of Gatsby users have mentioned it as well so would love to figure it out. This would also simplify creating custom Markdown React renderers e.g. footnotes that get rendered on a sidebar or as an inline widget which you click on to see the footnote.The text was updated successfully, but these errors were encountered: