diff options
author | 2024-01-17 13:14:53 +0000 | |
---|---|---|
committer | 2024-01-17 13:14:53 +0000 | |
commit | bc2edd4339a9f1619d57cd1eef22cc0da4073da4 (patch) | |
tree | 1ba2441baf922a0157c6a27c192fea1b0f048701 | |
parent | 165cfc154be477337037185c32b308616d1ed6fa (diff) | |
download | astro-bc2edd4339a9f1619d57cd1eef22cc0da4073da4.tar.gz astro-bc2edd4339a9f1619d57cd1eef22cc0da4073da4.tar.zst astro-bc2edd4339a9f1619d57cd1eef22cc0da4073da4.zip |
[ci] format
-rw-r--r-- | packages/astro/test/core-image-remark-imgattr.test.js | 4 | ||||
-rw-r--r-- | packages/markdown/remark/src/rehype-images.ts | 40 | ||||
-rw-r--r-- | packages/markdown/remark/test/remark-collect-images.test.js | 52 |
3 files changed, 52 insertions, 44 deletions
diff --git a/packages/astro/test/core-image-remark-imgattr.test.js b/packages/astro/test/core-image-remark-imgattr.test.js index 8d29d9c81..791014329 100644 --- a/packages/astro/test/core-image-remark-imgattr.test.js +++ b/packages/astro/test/core-image-remark-imgattr.test.js @@ -53,7 +53,9 @@ describe('astro:image', () => { it('Image src contains w=50 meaning getImage correctly used props added through the remark plugin', async () => { let $img = $('img'); - expect(new URL($img.attr('src'), 'http://example.com').searchParams.get('w')).to.equal('50'); + expect(new URL($img.attr('src'), 'http://example.com').searchParams.get('w')).to.equal( + '50' + ); }); }); }); 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]; + }); + } + } + }); + }; } diff --git a/packages/markdown/remark/test/remark-collect-images.test.js b/packages/markdown/remark/test/remark-collect-images.test.js index 5aed711b0..259bea96e 100644 --- a/packages/markdown/remark/test/remark-collect-images.test.js +++ b/packages/markdown/remark/test/remark-collect-images.test.js @@ -2,32 +2,38 @@ import { createMarkdownProcessor } from '../dist/index.js'; import chai from 'chai'; describe('collect images', async () => { - const processor = await createMarkdownProcessor(); + const processor = await createMarkdownProcessor(); - it('should collect inline image paths', async () => { - const { - code, - metadata: { imagePaths }, - } = await processor.render(`Hello `, { - fileURL: 'file.md', - }); + it('should collect inline image paths', async () => { + const { + code, + metadata: { imagePaths }, + } = await processor.render(`Hello `, { + fileURL: 'file.md', + }); - chai - .expect(code) - .to.equal('<p>Hello <img __ASTRO_IMAGE_="{"src":"./img.png","alt":"inline image url","index":0}"></p>'); + chai + .expect(code) + .to.equal( + '<p>Hello <img __ASTRO_IMAGE_="{"src":"./img.png","alt":"inline image url","index":0}"></p>' + ); - chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.png']); - }); + chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.png']); + }); - it('should add image paths from definition', async () => { - const { - code, - metadata: { imagePaths }, - } = await processor.render(`Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`, { - fileURL: 'file.md', - }); + it('should add image paths from definition', async () => { + const { + code, + metadata: { imagePaths }, + } = await processor.render(`Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`, { + fileURL: 'file.md', + }); - chai.expect(code).to.equal('<p>Hello <img __ASTRO_IMAGE_="{"src":"./img.webp","alt":"image ref","index":0}"></p>'); - chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.webp']); - }); + chai + .expect(code) + .to.equal( + '<p>Hello <img __ASTRO_IMAGE_="{"src":"./img.webp","alt":"image ref","index":0}"></p>' + ); + chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.webp']); + }); }); |