Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: migrating image borders #977

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions __tests__/compilers/compatability.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('compatability with RDMD', () => {
};

expect(mdx(ast).trim()).toMatchInlineSnapshot(`
"<Image align="center" width="300px" src="https://drastik.ch/wp-content/uploads/2023/06/blackcat.gif">
"<Image align="center" width="300px" src="https://drastik.ch/wp-content/uploads/2023/06/blackcat.gif" border={true}>
hello **cat**
</Image>"
`);
Expand Down Expand Up @@ -304,7 +304,8 @@ This is an image: <img src="http://example.com/#\\>" >
"Data Plane Setup"
],
"align": "center",
"caption": "Data Plane Setup"
"caption": "Data Plane Setup",
"border": true
}
]
}
Expand All @@ -313,7 +314,7 @@ This is an image: <img src="http://example.com/#\\>" >
const rmdx = mdx(rdmd.mdast(md));
expect(rmdx).toMatchInlineSnapshot(
`
"<Image alt="Data Plane Setup" src="https://files.readme.io/fd21f977cfbb9f55b3a13ab0b827525e94ee1576f21bbe82945cdc22cc966d82-Screenshot_2024-09-12_at_3.47.05_PM.png">
"<Image alt="Data Plane Setup" border={true} src="https://files.readme.io/fd21f977cfbb9f55b3a13ab0b827525e94ee1576f21bbe82945cdc22cc966d82-Screenshot_2024-09-12_at_3.47.05_PM.png">
Data Plane Setup
</Image>
"
Expand Down
2 changes: 2 additions & 0 deletions __tests__/transformers/images.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('images transformer', () => {
<Image
align="left"
alt="Some helpful text"
border
src="https://example.com/image.jpg"
title="Testing"
width="100px"
Expand All @@ -37,6 +38,7 @@ describe('images transformer', () => {

expect(tree.children[0].align).toBe('left');
expect(tree.children[0].alt).toBe('Some helpful text');
expect(tree.children[0].border).toBe(true);
expect(tree.children[0].title).toBe('Testing');
expect(tree.children[0].width).toBe('100px');
});
Expand Down
5 changes: 4 additions & 1 deletion processor/compile/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const html = (node: Html) => {
};

const figureToImageBlock = (node: any) => {
const { align, width, src, url, alt, title, ...image } = node.children.find((child: Node) => child.type === 'image');
const { align, border, width, src, url, alt, title, ...image } = node.children.find(
(child: Node) => child.type === 'image',
);
const { className } = image.data.hProperties;
const figcaption = node.children.find((child: Node) => child.type === 'figcaption');

Expand All @@ -49,6 +51,7 @@ const figureToImageBlock = (node: any) => {
...(align && { align }),
...(alt && { alt }),
...(className && { border: className === 'border' }),
...(border && { border }),
...(caption && { caption }),
...(title && { title }),
...(width && { width }),
Expand Down
5 changes: 4 additions & 1 deletion processor/transform/readme-to-mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const readmeToMdx = (): Transform => tree => {
parent.children.splice(index, 1, {
type: 'mdxJsxFlowElement',
name: 'Image',
attributes: toAttributes({ ...image, src: image.src || image.url }, imageAttrs),
attributes: toAttributes(
{ ...image, border: image.data.hProperties.className === 'border', src: image.src || image.url },
imageAttrs,
),
children: caption.children,
});
});
Expand Down
Loading