wooorm / markdown-rs

CommonMark compliant markdown parser in Rust with ASTs and extensions
https://docs.rs/markdown/1.0.0-alpha.21/markdown/
MIT License
966 stars 53 forks source link

Fix parsing of JSX with expression #138

Closed begleynk closed 2 months ago

begleynk commented 2 months ago

Disclaimer: I am not entirely sure that this is the correct fix, but it does pass the tests. Happy to make changes in the likely case I haven't quite understood this fully.

This fixes the issues mentioned in #136, where this case <x>{1}</x> was no longer parsed, and {1}<x/> caused a panic when converted into an AST (not an issue when converting to HTML).

I was first confused about what the expected output should be here, so I looked at micromark for inspiration. Here's what I found:

This change now makes this crate matches micromark's behavior.

Test program I used ```js import {mdxjs} from 'micromark-extension-mdxjs' import {fromMarkdown} from 'mdast-util-from-markdown' import {mdxFromMarkdown} from 'mdast-util-mdx' const doc = "{1}"; const tree = fromMarkdown(doc, { extensions: [mdxjs()], mdastExtensions: [mdxFromMarkdown()] }) console.log(JSON.stringify(tree, null, 2)) ```

This also removes the MdxExpressionFlowNok part of the state, as it wasn't used any more.

Fixes #136

wooorm commented 2 months ago

thanks!