Skip to content

Commit

Permalink
feat: Create comment component for markdown pages
Browse files Browse the repository at this point in the history
 - this component does not render in the UI
 - this component is not translated
  • Loading branch information
tabathadelane committed Jun 9, 2023
1 parent dcc4425 commit 10475b0
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@ exports[`serializes Link to html 1`] = `
"
`;
exports[`serializes MDXComment to html with "notranslate" class 1`] = `
"
<div data-type=\\"component\\" data-component=\\"WARNING\\" class=\\"notranslate\\">
<p>This is a note to future authors about the MDX content.</p>
<p>It does not render in the UI</p>
</div>
"
`;
exports[`serializes Side components to html 1`] = `
"
<div data-type=\\"component\\" data-component=\\"Side\\">
Expand Down
14 changes: 14 additions & 0 deletions scripts/actions/__tests__/deserialize-html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,17 @@ test('deserializes InlineSignup component', async () => {
const mdx = await deserializeHTML(await serializeMDX(input));
expect(mdx).toEqual(input);
});

test('deserializes MDXComment component', async () => {
const input = `
<WARNING>
This is a note to future authors about the MDX content.
It does not render in the UI
</WARNING>
`;

const mdx = await deserializeHTML(await serializeMDX(input));

expect(mdx).toEqual(input.trim());
});
12 changes: 12 additions & 0 deletions scripts/actions/__tests__/serialize-mdx.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,15 @@ test('serialize InlineSignup component', async () => {
const html = await serializeMDX(mdx);
expect(html).toMatchSnapshot();
});

test('serializes MDXComment to html with "notranslate" class', async () => {
const html = await serializeMDX(`
<WARNING>
This is a note to future authors about the MDX content.
It does not render in the UI
</WARNING>
`);

expect(html).toMatchSnapshot();
});
8 changes: 8 additions & 0 deletions scripts/actions/utils/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ module.exports = {
wrapChildren: false,
}),
},
WARNING: {
deserialize: deserializeComponent,
serialize: (h, node) =>
serializeComponent(h, node, {
classNames: 'notranslate',
wrapChildren: false,
}),
},
ExternalLink: {
deserialize: deserializeComponent,
serialize: serializeComponent,
Expand Down
16 changes: 16 additions & 0 deletions src/components/MDXComment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import styled from '@emotion/styled';
import PropTypes from 'prop-types';

// This component is not rendered in the UI and is not translated
const MDXComment = ({ children }) => <Comment>{children}</Comment>;

MDXComment.propTypes = {
children: PropTypes.node,
};

const Comment = styled.div`
display: none;
`;

export default MDXComment;
2 changes: 2 additions & 0 deletions src/components/MDXContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import InlinePopover from './InlinePopover';
import InstallFeedback from './InstallFeedback';
import MDXButton from './MDXButton';
import MDXButtonGroup from './MDXButtonGroup';
import MDXComment from './MDXComment';
import MDXTechTileGrid from './MDXTechTileGrid';
import PropTypes from 'prop-types';
import React from 'react';
Expand Down Expand Up @@ -90,6 +91,7 @@ const defaultComponents = {
ButtonLink: (props) => <MDXButton as={Link} {...props} />,
ButtonGroup: MDXButtonGroup,
DoNotTranslate: ({ children }) => <>{children}</>,
WARNING: MDXComment,
Tabs: Tabs,
TabsBar: Tabs.Bar,
TabsBarItem: Tabs.BarItem,
Expand Down

0 comments on commit 10475b0

Please sign in to comment.