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 captions #971

Merged
merged 1 commit into from
Sep 25, 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
29 changes: 29 additions & 0 deletions __tests__/compilers/compatability.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,33 @@ This is an image: <img src="http://example.com/#\\>" >

expect(rmdx).toMatch('<Image align="center" width="250px" src="https://files.readme.io/4a1c7a0-Iphone.jpeg" />');
});

it('can parse and transform magic image block AST to MDX with caption', () => {
const md = `
[block:image]
{
"images": [
{
"image": [
"https://files.readme.io/fd21f977cfbb9f55b3a13ab0b827525e94ee1576f21bbe82945cdc22cc966d82-Screenshot_2024-09-12_at_3.47.05_PM.png",
"",
"Data Plane Setup"
],
"align": "center",
"caption": "Data Plane Setup"
}
]
}
[/block]`;

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">
Data Plane Setup
</Image>
"
`,
);
});
});
2 changes: 1 addition & 1 deletion processor/transform/readme-to-mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const readmeToMdx = (): Transform => tree => {
parent.children.splice(index, 1, {
type: 'mdxJsxFlowElement',
name: 'Image',
attributes: toAttributes(image, imageAttrs),
attributes: toAttributes({ ...image, src: image.src || image.url }, imageAttrs),
children: caption.children,
});
});
Expand Down
2 changes: 1 addition & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface Figure extends Node {
data: {
hName: 'figure';
};
children: [ImageBlock, FigCaption];
children: [ImageBlock & { url: string }, FigCaption];
}

interface FigCaption extends Node {
Expand Down
Loading