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:
Micromark parses <x>{1}</x> as a block level Flow element with an expression (unlike this crate as of alpha.16, which produced a paragraph with an inline JSX text node)
Micromark parses {1}</x> into an AST with a root element, with two children: the expr, and the JSX tag
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.
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:
<x>{1}</x>
as a block level Flow element with an expression (unlike this crate as of alpha.16, which produced a paragraph with an inline JSX text node){1}</x>
into an AST with aroot
element, with two children: the expr, and the JSX tagThis 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