remark-collect-images.test.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import assert from 'node:assert/strict';
  2. import { describe, it, before } from 'node:test';
  3. import { createMarkdownProcessor } from '../dist/index.js';
  4. describe('collect images', async () => {
  5. let processor;
  6. before(async () => {
  7. processor = await createMarkdownProcessor();
  8. });
  9. it('should collect inline image paths', async () => {
  10. const markdown = `Hello ![inline image url](./img.png)`;
  11. const fileURL = 'file.md';
  12. const {
  13. code,
  14. metadata: { imagePaths },
  15. } = await processor.render(markdown, { fileURL });
  16. assert.equal(
  17. code,
  18. '<p>Hello <img __ASTRO_IMAGE_="{&#x22;src&#x22;:&#x22;./img.png&#x22;,&#x22;alt&#x22;:&#x22;inline image url&#x22;,&#x22;index&#x22;:0}"></p>'
  19. );
  20. assert.deepEqual(Array.from(imagePaths), ['./img.png']);
  21. });
  22. it('should add image paths from definition', async () => {
  23. const markdown = `Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`;
  24. const fileURL = 'file.md';
  25. const { code, metadata } = await processor.render(markdown, { fileURL });
  26. assert.equal(
  27. code,
  28. '<p>Hello <img __ASTRO_IMAGE_="{&#x22;src&#x22;:&#x22;./img.webp&#x22;,&#x22;alt&#x22;:&#x22;image ref&#x22;,&#x22;index&#x22;:0}"></p>'
  29. );
  30. assert.deepEqual(Array.from(metadata.imagePaths), ['./img.webp']);
  31. });
  32. });