Skip to content

Commit

Permalink
fix(fusuma-loader): replace class with className
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Jul 4, 2019
1 parent f539cbf commit 48d0f73
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
47 changes: 47 additions & 0 deletions packages/mdx-loader/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,53 @@ export default function MDXContent({
MDXContent.isMDXComponent = true;"
`;

exports[`fusuma-loader should convert class to className 1`] = `
"/* @jsx mdx */


import React from 'react';
import { mdx } from '@mdx-js/react';
export const slides = [
(props) => (
<>

<h1>{\`Class\`}</h1>
<div className=\\"test\\">
<div className=\\"test2\\">
<h2 className=\\"test3\\">hello</h2>
</div>
</div>

</>
)];
export const fusumaProps = [{}];
const makeShortcode = name => function MDXDefaultShortcode(props) {
console.warn(\\"Component \\" + name + \\" was not imported, exported, or provided by MDXProvider as global scope\\")
return <div {...props}/>
};

const layoutProps = {
slides
};
const MDXLayout = \\"wrapper\\"
export default function MDXContent({
components,
...props
}) {
return <MDXLayout {...layoutProps} {...props} components={components} mdxType=\\"MDXLayout\\">
<h1>{\`Class\`}</h1>
<div className=\\"test\\">
<div className=\\"test2\\">
<h2 className=\\"test3\\">hello</h2>
</div>
</div>

</MDXLayout>;
}

MDXContent.isMDXComponent = true;"
`;

exports[`fusuma-loader should convert emoji 1`] = `
"/* @jsx mdx */

Expand Down
13 changes: 13 additions & 0 deletions packages/mdx-loader/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ graph TD;
$$
a^2 + b^2 = c^2
$$
`;
expect(await transformToJS(src)).toMatchSnapshot();
});

test('should convert class to className', async () => {
const src = `
# Class
<div class="test">
<div class="test2">
<h2 class="test3">hello</h2>
</div>
</div>
`;
expect(await transformToJS(src)).toMatchSnapshot();
});
Expand Down
4 changes: 3 additions & 1 deletion packages/mdx-loader/src/mdxPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ function mdxPlugin() {
slide.push(n);

if (n.type === 'jsx') {
n.value = n.value.replace(/src="(.+?\.(png|jpg|gif|svg?))"/, 'src={require("$1")}');
n.value = n.value
.replace(/src="(.+?\.(png|jpg|gif|svg?))"/, 'src={require("$1")}')
.replace(/class=/g, 'className=');
}
}
});
Expand Down

0 comments on commit 48d0f73

Please sign in to comment.