0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00
astro/packages/integrations/mdx/test/fixtures/image-remark-imgattr/remarkPlugin.js
Oliver Speir df37366556
MDX remark image props (#9753)
* rearrange plugins and add props to Image component

* add tests and update lockfile

* add changeset

* re-rearrange plugin order, gfm/smartypants then user defined then image related then shiki/prism

* make more generic

* add more/better tests

* remove unused logger

---------

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
2024-01-23 18:18:09 -05:00

22 lines
530 B
JavaScript

export default function plugin() {
return transformer;
function transformer(tree) {
function traverse(node) {
if (node.type === "image") {
node.data = node.data || {};
node.data.hProperties = node.data.hProperties || {};
node.data.hProperties.id = "test";
node.data.hProperties.width = "300";
node.data.hProperties.widths = [300,600];
node.data.hProperties.sizes = "(min-width: 600px) 600w, 300w";
}
if (node.children) {
node.children.forEach(traverse);
}
}
traverse(tree);
}
}