2023-09-14 10:22:16 +00:00
|
|
|
import { createMarkdownProcessor } from '../dist/index.js';
|
2023-09-13 15:29:39 +00:00
|
|
|
import chai from 'chai';
|
|
|
|
|
2023-09-14 10:22:16 +00:00
|
|
|
describe('collect images', async () => {
|
|
|
|
const processor = await createMarkdownProcessor();
|
|
|
|
|
2023-09-13 15:29:39 +00:00
|
|
|
it('should collect inline image paths', async () => {
|
2023-09-14 10:22:16 +00:00
|
|
|
const {
|
|
|
|
code,
|
|
|
|
metadata: { imagePaths },
|
|
|
|
} = await processor.render(`Hello ![inline image url](./img.png)`, {
|
|
|
|
fileURL: 'file.md',
|
|
|
|
});
|
2023-09-13 15:29:39 +00:00
|
|
|
|
|
|
|
chai
|
|
|
|
.expect(code)
|
|
|
|
.to.equal('<p>Hello <img alt="inline image url" __ASTRO_IMAGE_="./img.png"></p>');
|
|
|
|
|
2023-09-14 10:22:16 +00:00
|
|
|
chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.png']);
|
2023-09-13 15:29:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should add image paths from definition', async () => {
|
2023-09-14 10:22:16 +00:00
|
|
|
const {
|
|
|
|
code,
|
|
|
|
metadata: { imagePaths },
|
|
|
|
} = await processor.render(`Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`, {
|
|
|
|
fileURL: 'file.md',
|
|
|
|
});
|
2023-09-13 15:29:39 +00:00
|
|
|
|
|
|
|
chai.expect(code).to.equal('<p>Hello <img alt="image ref" __ASTRO_IMAGE_="./img.webp"></p>');
|
2023-09-14 10:22:16 +00:00
|
|
|
chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.webp']);
|
2023-09-13 15:29:39 +00:00
|
|
|
});
|
|
|
|
});
|