2023-09-14 05:22:16 -05:00
|
|
|
import { createMarkdownProcessor } from '../dist/index.js';
|
2023-09-13 10:29:39 -05:00
|
|
|
import chai from 'chai';
|
|
|
|
|
2023-09-14 05:22:16 -05:00
|
|
|
describe('collect images', async () => {
|
2024-01-17 08:14:53 -05:00
|
|
|
const processor = await createMarkdownProcessor();
|
2023-09-14 05:22:16 -05:00
|
|
|
|
2024-01-17 08:14:53 -05:00
|
|
|
it('should collect inline image paths', async () => {
|
|
|
|
const {
|
|
|
|
code,
|
|
|
|
metadata: { imagePaths },
|
|
|
|
} = await processor.render(`Hello ![inline image url](./img.png)`, {
|
|
|
|
fileURL: 'file.md',
|
|
|
|
});
|
2023-09-13 10:29:39 -05:00
|
|
|
|
2024-01-17 08:14:53 -05:00
|
|
|
chai
|
|
|
|
.expect(code)
|
|
|
|
.to.equal(
|
|
|
|
'<p>Hello <img __ASTRO_IMAGE_="{"src":"./img.png","alt":"inline image url","index":0}"></p>'
|
|
|
|
);
|
2023-09-13 10:29:39 -05:00
|
|
|
|
2024-01-17 08:14:53 -05:00
|
|
|
chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.png']);
|
|
|
|
});
|
2023-09-13 10:29:39 -05:00
|
|
|
|
2024-01-17 08:14:53 -05:00
|
|
|
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',
|
|
|
|
});
|
2023-09-13 10:29:39 -05:00
|
|
|
|
2024-01-17 08:14:53 -05:00
|
|
|
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']);
|
|
|
|
});
|
2023-09-13 10:29:39 -05:00
|
|
|
});
|