diff options
Diffstat (limited to 'packages/markdown/remark/src/rehype-images.ts')
-rw-r--r-- | packages/markdown/remark/src/rehype-images.ts | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/packages/markdown/remark/src/rehype-images.ts b/packages/markdown/remark/src/rehype-images.ts index 9f9b9ee46..71783ca1a 100644 --- a/packages/markdown/remark/src/rehype-images.ts +++ b/packages/markdown/remark/src/rehype-images.ts @@ -3,28 +3,28 @@ import type { MarkdownVFile } from './types.js'; export function rehypeImages() { return () => - function (tree: any, file: MarkdownVFile) { - const imageOccurrenceMap = new Map(); + function (tree: any, file: MarkdownVFile) { + const imageOccurrenceMap = new Map(); - visit(tree, (node) => { - if (node.type !== 'element') return; - if (node.tagName !== 'img') return; + visit(tree, (node) => { + if (node.type !== 'element') return; + if (node.tagName !== 'img') return; - if (node.properties?.src) { - if (file.data.imagePaths?.has(node.properties.src)) { - const { ...props } = node.properties; + if (node.properties?.src) { + if (file.data.imagePaths?.has(node.properties.src)) { + const { ...props } = node.properties; - // Initialize or increment occurrence count for this image - const index = imageOccurrenceMap.get(node.properties.src) || 0; - imageOccurrenceMap.set(node.properties.src, index + 1); + // Initialize or increment occurrence count for this image + const index = imageOccurrenceMap.get(node.properties.src) || 0; + imageOccurrenceMap.set(node.properties.src, index + 1); - node.properties['__ASTRO_IMAGE_'] = JSON.stringify({ ...props, index }); - - Object.keys(props).forEach((prop) => { - delete node.properties[prop]; - }); - } - } - }); - }; + node.properties['__ASTRO_IMAGE_'] = JSON.stringify({ ...props, index }); + + Object.keys(props).forEach((prop) => { + delete node.properties[prop]; + }); + } + } + }); + }; } |