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.

remark-mdx: empty line before closing tag issue

See original GitHub issue

Subject 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:closed
  • Created 4 years ago
  • Reactions:21
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
wooormcommented, Apr 23, 2020

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!

4reactions
seanhealycommented, Feb 11, 2020

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?

Read more comments on GitHub >

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

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