Skip to content

Commit

Permalink
wrapper replacement (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBiscardi authored and johno committed Mar 21, 2019
1 parent b44aa5d commit 410d43c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
13 changes: 6 additions & 7 deletions packages/mdx/mdx-hast-to-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,18 @@ function toJSX(node, parentNode = {}, options = {}) {
`const layoutProps = {
${exportNames.join(',\n')}
};
${layout ? `const MDXLayout = ${layout}` : ''}
const MDXLayout = ${layout ? layout : '"wrapper"'}
${
skipExport ? '' : 'export default'
} function MDXContent({ components, ...props }) {
return (
<div
name="wrapper"
<MDXLayout
{...layoutProps}
{...props}
components={components}>
${layout ? `<MDXLayout {...layoutProps} {...props}>` : ''}
${jsxNodes.map(childNode => toJSX(childNode, node)).join('')}
${layout ? `</MDXLayout>` : ''}
</div>
)
</MDXLayout>
)
}
MDXContent.isMDXComponent = true`
)
Expand Down
17 changes: 8 additions & 9 deletions packages/mdx/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ it('Should match sample blog post snapshot', async () => {
"/* @jsx mdx */
const layoutProps = {};
const MDXLayout = \\"wrapper\\";
export default function MDXContent({ components, ...props }) {
return (
<div name=\\"wrapper\\" components={components}>
<MDXLayout {...layoutProps} {...props} components={components}>
<h1>{\`Hello World\`}</h1>
</div>
</MDXLayout>
);
}
MDXContent.isMDXComponent = true;
Expand Down Expand Up @@ -375,10 +375,10 @@ const layoutProps = {
const MDXLayout = ({children}) => <div>{children}</div>
export default function MDXContent({ components, ...props }) {
return (
<div
name=\\"wrapper\\"
<MDXLayout
{...layoutProps}
{...props}
components={components}>
<MDXLayout {...layoutProps} {...props}>
<h1>{\`Hello, world!\`}</h1>
Expand Down Expand Up @@ -426,9 +426,8 @@ export default function MDXContent({ components, ...props }) {
\\\\\`};
\\\\\`
\`}</code></pre>
</MDXLayout>
</div>
)
</MDXLayout>
)
}
MDXContent.isMDXComponent = true"
`)
Expand Down
11 changes: 5 additions & 6 deletions packages/remark-mdx/test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ const layoutProps = {
const MDXLayout = Foo
export default function MDXContent({ components, ...props }) {
return (
<div
name=\\"wrapper\\"
<MDXLayout
{...layoutProps}
{...props}
components={components}>
<MDXLayout {...layoutProps} {...props}>
<h1>{\`Hello, world! \`}<Foo bar={{ baz: 'qux' }} /></h1>
<Baz>
Hi!
</Baz>
</MDXLayout>
</div>
)
</MDXLayout>
)
}
MDXContent.isMDXComponent = true"
`;
Expand Down

0 comments on commit 410d43c

Please sign in to comment.