Skip to content

Commit

Permalink
WIP: add serialize function to handler for DoNotTranslate component
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkmcadoo committed Dec 2, 2021
1 parent 9fb8254 commit 844be5c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion scripts/actions/__tests__/serialize-mdx.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import serializeMDX from '../serialize-mdx';
import fs from 'fs';

test.only('test DoNotTranslate', async () => {
const html = await serializeMDX(`
<DoNotTranslate>
Not all who wander are lost...
</DoNotTranslate>
`);

expect(html).toMatchSnapshot();
});

test('serializes Button to html', async () => {
const html = await serializeMDX(`
<Button
variant="normal"
variant="primary"
>
View all C SDK docs
</Button>
Expand Down
13 changes: 13 additions & 0 deletions scripts/actions/utils/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ module.exports = {
serialize: (h, node) =>
serializeComponent(h, node, { textAttributes: ['title'] }),
},
DoNotTranslate: {
deserialize:
serialize: (h, node) => {
const result = h(node, 'div', {
'data-type': 'component',
'data-component': 'DoNotTranslate',
'data-props': Buffer.from(JSON.stringify(node.children)).toString(
'base64'
),
});
return result;
},
},
thead: {
deserialize: deserializeComponent,
serialize: (h, node) =>
Expand Down
1 change: 1 addition & 0 deletions src/components/MDXContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const defaultComponents = {
Button: MDXButton,
ButtonLink: (props) => <MDXButton as={Link} {...props} />,
ButtonGroup: MDXButtonGroup,
DoNotTranslate: ({ children }) => <>{children}</>,
};

const MDXContainer = ({ body, children, components }) => {
Expand Down

0 comments on commit 844be5c

Please sign in to comment.