remark-mdx: empty line before closing tag issue
See original GitHub issueSubject of the issue
The issue causes parsing failure in a compiler plugin that parses the child.value strings for post processing.
Reproduce
The following:
<button>
<div>hello world</div>
//<- there is one empty space here at the start of the line
</button>
will parse as
"children": [
{
"type": "jsx",
"value": "<button>\n <div>hello world</div>\n\n</button>\n\n",
...
}
],
However, removing the one space on the empty line will parse as 3 separate elements:
<button>
<div>hello world</div>
//<- there is no empty space here
</button>
"children": [
{
"type": "jsx",
"value": "<button>\n <div>hello world</div>",
},
{
"type": "text",
"value": "\n"
},
{
"type": "jsx",
"value": "</button>",
}
],
Potential solution
The issue seems to be here: https://github.com/mdx-js/mdx/blob/dec55ec92f9ff42b0ae3617f0168a387e56f7ff8/packages/remark-mdx/block.js#L101
Since an empty string will always pass the test, the closing tag is missed if there is an empty line before it.
Any reasons not to change the rule to
...
if (line.length && sequence[1].test(line)) {
index = next
break
}
...
Issue Analytics
- State:
- Created 4 years ago
- Reactions:21
- Comments:15 (5 by maintainers)
Top Results From Across the Web
Troubleshooting MDX
If there is a closing brace somewhere, make sure that the braces are each on their own lines with no text before the...
Read more >Create two blank lines in Markdown - Stack Overflow
A line break (not in a code span or HTML tag) that is preceded by two or more spaces and does not occur...
Read more >How to add a blank line or line break to markdown content?
To add multiple lines, Use the <pre> tag to preserve line break. The content inside pre tag is not parsed, so, just add...
Read more >block-closing-brace-empty-line-before - Stylelint
Require or disallow an empty line before the closing brace of blocks. The fix option can automatically fix all of the problems reported...
Read more >Guide to Writing MDX and Markdown | Chicago Docs
This is the second line. ... This is the first line. This is the second line. Be sure to use the self-closing syntax...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for all your comments folks! We’re working on adding proper JSX parsing. 2.0.0 will solve many of the JSX parsing issues, including this one!
This is still being problematic for us. Removing empty lines isn’t great as it leaves the example code harder to read. Has anyone found a reliable way of preventing Prettier from stripping trailing whitespace within mdx Playground blocks?