MDX: empty lines inside JSX blocks
See original GitHub issuePrettier 1.16.1 Playground link
# Options (if any):
--single-quote
Input:
## Basic usage
<Playground>
{() => {
const message = 'Hello world'
return (
<Alert>{message}</Alert>
)
}}
</Playground>
Output:
SyntaxError: Unexpected token (3:34)
1 | <Playground>
2 | {() => {
> 3 | const message = 'Hello world'
| ^
Expected behavior:
## Basic usage
<Playground>
{() => {
const message = 'Hello world';
return (
<Alert>{message}</Alert>
);
}}
</Playground>
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:16 (7 by maintainers)
Top Results From Across the Web
mdx-observable - npm
Currently (Aug 2018) the MDX parser doesn't allow putting blank lines inside of JSX blocks. If you see an error about "adjacent elements",...
Read more >Guide to Writing MDX and Markdown | Chicago Docs
A block quote can contain other Markdown formatting as well as blank lines and nested block quotes. Nested block quotes are created using...
Read more >React Hooks in MDX
Note: It's important that you don't include any empty lines in the code block since there's currently a parsing bug that will hopefully...
Read more >Code blocks | Docusaurus
Note that the empty lines above and below each language block are intentional. This is a current limitation of MDX: you have to...
Read more >How to add new line in Markdown presentation?
The implication of the “one or more consecutive lines of text” rule is that Markdown ... You could use in R markdown...
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 Free
Top 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
I also ran into this issue 😞
This block:
Gets corrected to:
Our team uses docz too and we also have this issue. Removing empty lines from the mdx examples above seems to help.
Looks like React formatting is successful only when the entire node is parsed as a single markdown paragraph before the JSX parser comes into play. If you add spaces to the lines after
const
and}}
here, formatting will work once:Playground
However, the following formatting of the result will be unsuccessful, because after the spaces are removed from the empty lines, we’ve ended up with two markdown paragraphs again. This means that both React nodes are now partial and thus unparsable.
UPD: Another example (jsx only, no functional components and js statements):