Skip to content

Commit 1c5e880

Browse files
Merge branch 'next'
2 parents 0f3db74 + afa40af commit 1c5e880

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

__tests__/compilers/compatability.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,33 @@ This is an image: <img src="http://example.com/#\\>" >
291291

292292
expect(rmdx).toMatch('<Image align="center" width="250px" src="https://files.readme.io/4a1c7a0-Iphone.jpeg" />');
293293
});
294+
295+
it('can parse and transform magic image block AST to MDX with caption', () => {
296+
const md = `
297+
[block:image]
298+
{
299+
"images": [
300+
{
301+
"image": [
302+
"https://files.readme.io/fd21f977cfbb9f55b3a13ab0b827525e94ee1576f21bbe82945cdc22cc966d82-Screenshot_2024-09-12_at_3.47.05_PM.png",
303+
"",
304+
"Data Plane Setup"
305+
],
306+
"align": "center",
307+
"caption": "Data Plane Setup"
308+
}
309+
]
310+
}
311+
[/block]`;
312+
313+
const rmdx = mdx(rdmd.mdast(md));
314+
expect(rmdx).toMatchInlineSnapshot(
315+
`
316+
"<Image alt="Data Plane Setup" src="https://files.readme.io/fd21f977cfbb9f55b3a13ab0b827525e94ee1576f21bbe82945cdc22cc966d82-Screenshot_2024-09-12_at_3.47.05_PM.png">
317+
Data Plane Setup
318+
</Image>
319+
"
320+
`,
321+
);
322+
});
294323
});

processor/transform/readme-to-mdx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const readmeToMdx = (): Transform => tree => {
3131
parent.children.splice(index, 1, {
3232
type: 'mdxJsxFlowElement',
3333
name: 'Image',
34-
attributes: toAttributes(image, imageAttrs),
34+
attributes: toAttributes({ ...image, src: image.src || image.url }, imageAttrs),
3535
children: caption.children,
3636
});
3737
});

types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ interface Figure extends Node {
4949
data: {
5050
hName: 'figure';
5151
};
52-
children: [ImageBlock, FigCaption];
52+
children: [ImageBlock & { url: string }, FigCaption];
5353
}
5454

5555
interface FigCaption extends Node {

0 commit comments

Comments
 (0)