-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix(mdxast): render props parse case #140
Conversation
packages/mdxast/test/test.js
Outdated
@@ -30,7 +33,11 @@ const parseFixture = str => { | |||
} | |||
|
|||
test('it parses a file', () => { | |||
const result = parseFixture(fixture) | |||
const result = parseFixture(fixture.basic) | |||
expect(result).toMatchSnapshot() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use babel to parse the result? It's much more reliable than having a snapshot test that will be guaranteed to fail on every little change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good, I can do that ✌️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
@timneutkens do you think that just this case is fine? |
I wonder if there's a reason as to why remark doesn't parse multi-paragraph html / if there's an easier way to fix this. cc @wooorm. Example:
compiles to:
Whereas
Compiles to
Results taken from https://astexplorer.net/ |
@timneutkens It does “block” HTML if it’s a known HTML block element. Would it be possible to detect the imported components, and pass their names to the processor as “blocks”? |
@wooorm we kind of hijacked that option https://github.com/mdx-js/mdx/blob/master/packages/mdx/index.js#L11 to use a regex 🕵️ So I guess astexplorer is not a great example 😅 |
I think that remark doesn't parse multi-paragraph because it assumes that document is just a html, that no reason to use a function inside it like in jsx! But render a component with some render callbacks is something that the community are embracing a lot, limit or create some workarounds in think that isn't a good option. IMHO, the better choice would be the language works like expect! |
@pedronauck the thing is that anything inside jsx tags is not some special case, it should just be 1 big jsx block meaning it'd work fine if the parser turns it into that. But I'll have to check the remark code again, specifically the part @wooorm was pointing out, since in that case we don't even have to change that much on our side of the parser 😄
Note that remark just says: everything inside html is text, so it has nothing to do with it having to know what the content is, since mdx doesn't parse jsx tags, it just puts it into the final document without touching it. |
I agree in some points, but I think that |
Nothing more about that @timneutkens ? |
What is missing to merge this PR? |
Close in favor of the new algorithms that extends remark parser |
This pr just add mergeNodeWithoutCloseTag method in the
mdxast
parser that check if some node has just the element open tag without close it, then merging values into the correct node making a reverse iteration over the tree and deleting incorreting nodes.I stressed some cases with a new snapshot test and looking over it is everything going fine!
This closes #139, closes #136 and closes #137