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: support Markdown inside JSX blocks

See original GitHub issue

According to the commonmark spec, it seems that the example below is valid MDX. However, Prettier is throwing an error.

Prettier 1.19.1 Playground link

--parser mdx

Input:

<CodeSurfer>

```js
console.log(1);
```

</CodeSurfer>

Output:

SyntaxError: Unexpected closing tag "CodeSurfer". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (1:1)
> 1 | <CodeSurfer>
    | ^
  2 | 
  3 | ```js
  4 | console.log(1);

Expected behavior:

If this is valid MDX it should parse it and format it without an error.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:35 (29 by maintainers)

github_iconTop GitHub Comments

12reactions
karlhorkycommented, Jan 27, 2020

Sure, although it has been fixed actually. 🤣

Where has this been fixed? In an unreleased version of Prettier?

Ah actually, thanks to @kachkaev’s comment (https://github.com/prettier/prettier/issues/7176#issuecomment-571218217), I just tried adding "prettier": "prettier/prettier" to my devDependencies and it seems to format with all examples here! 🚀

Show gif

Kapture 2020-01-27 at 11 23 34

So it looks like this will be fixed as soon as Prettier 1.20.0 or 1.19.2 is released. 🙌

Workaround for now:

Change your version of Prettier in your package.json to "prettier": "prettier/prettier". If you’re using VS Code, this new local version will be picked up automatically by prettier-vscode.

3reactions
bsgreenbcommented, May 13, 2020

This issue has been solved for me via npm i -D prettier@latest

Read more comments on GitHub >

github_iconTop Results From Across the Web

MDX: Markdown for the component era
MDX allows you to use JSX in your markdown content. You can import components, such as interactive charts or alerts, and embed them...
Read more >
Guide to Writing MDX and Markdown | Chicago Docs
MDX is a combination of Markdown and JSX, and regular Markdown syntax can be used for most formatting. What follows is a guide...
Read more >
MDX and React - Docusaurus
Docusaurus has built-in support for MDX v1, which allows you to write JSX within your Markdown files and render them as React components....
Read more >
MDX Format - Storybook - JS.ORG
MDX is a standard file format that combines Markdown with JSX. It means you can use Markdown's terse syntax (such as # heading...
Read more >
MDX - JSX in Markdown - DEV Community ‍ ‍
There is a new markup-language on the block, called MDX, which is essentially Markdown sprinkeled with JSX elements and JavaScript import s.
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