question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MDX: empty lines inside JSX blocks

See original GitHub issue

Prettier 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:open
  • Created 5 years ago
  • Reactions:8
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
brandonweisscommented, Apr 1, 2019

I also ran into this issue 😞

This block:

// index.html.mdx
import Layout from "./layout.html.jsx"

export const layout = (props) => (
  <Layout title="Title">
    {props.children}
  </Layout>
)

# Heading

Gets corrected to:

// index.html.mdx
import Layout from "./layout.html.jsx"

export const layout = (props) => (
<Layout title="Title">
{props.children}
</Layout>
)

# Heading
4reactions
kachkaevcommented, Jan 24, 2019

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>
  {() => {
    const message    = "Hello world"
    
    return <Alert   >{message}</Alert   >
  }}
  
</Playground>

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):

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found