Skip to content

Commit

Permalink
fix(mdx): treat jsx codeblock same as in markdown (#5391)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Nov 9, 2018
1 parent 7f472d7 commit 469a831
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/language-js/printer-estree.js
Expand Up @@ -6269,7 +6269,7 @@ function isUnitTestSetUp(n) {
}

function isTheOnlyJSXElementInMarkdown(options, path) {
if (options.parentParser !== "markdown") {
if (options.parentParser !== "markdown" && options.parentParser !== "mdx") {
return false;
}

Expand Down
42 changes: 42 additions & 0 deletions tests/mdx/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -198,6 +198,48 @@ exports[`jsx.mdx - mdx-verify 2`] = `
`;

exports[`jsx-codeblock.mdx - mdx-verify 1`] = `
\`\`\`jsx
<div>foo</div>
\`\`\`
\`\`\`jsx
const a = 1;
<div>foo</div>;
\`\`\`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\`\`\`jsx
<div>foo</div>
\`\`\`
\`\`\`jsx
const a = 1;
<div>foo</div>;
\`\`\`
`;

exports[`jsx-codeblock.mdx - mdx-verify 2`] = `
\`\`\`jsx
<div>foo</div>
\`\`\`
\`\`\`jsx
const a = 1;
<div>foo</div>;
\`\`\`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\`\`\`jsx
<div>foo</div>
\`\`\`
\`\`\`jsx
const a = 1
;<div>foo</div>
\`\`\`
`;

exports[`mixed.mdx - mdx-verify 1`] = `
import { Baz } from './Fixture'
import { Buz } from './Fixture'
Expand Down
8 changes: 8 additions & 0 deletions tests/mdx/jsx-codeblock.mdx
@@ -0,0 +1,8 @@
```jsx
<div>foo</div>
```

```jsx
const a = 1;
<div>foo</div>;
```

0 comments on commit 469a831

Please sign in to comment.