2024-02-12 07:25:29 -05:00
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { before, describe, it } from 'node:test';
|
2023-09-14 05:22:16 -05:00
|
|
|
import { createMarkdownProcessor } from '../dist/index.js';
|
2023-09-13 10:29:39 -05:00
|
|
|
|
2023-09-14 05:22:16 -05:00
|
|
|
describe('collect images', async () => {
|
2024-02-12 07:25:29 -05:00
|
|
|
let processor;
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
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 () => {
|
2024-02-12 07:25:29 -05:00
|
|
|
const markdown = `Hello ![inline image url](./img.png)`;
|
|
|
|
const fileURL = 'file.md';
|
|
|
|
|
2024-01-17 08:14:53 -05:00
|
|
|
const {
|
|
|
|
code,
|
|
|
|
metadata: { imagePaths },
|
2024-02-12 07:25:29 -05:00
|
|
|
} = await processor.render(markdown, { fileURL });
|
2023-09-13 10:29:39 -05:00
|
|
|
|
2024-02-12 07:25:29 -05:00
|
|
|
assert.equal(
|
|
|
|
code,
|
|
|
|
'<p>Hello <img __ASTRO_IMAGE_="{"src":"./img.png","alt":"inline image url","index":0}"></p>'
|
|
|
|
);
|
2023-09-13 10:29:39 -05:00
|
|
|
|
2024-02-16 06:41:16 -05:00
|
|
|
assert.deepEqual(Array.from(imagePaths), ['./img.png']);
|
2024-01-17 08:14:53 -05:00
|
|
|
});
|
2023-09-13 10:29:39 -05:00
|
|
|
|
2024-01-17 08:14:53 -05:00
|
|
|
it('should add image paths from definition', async () => {
|
2024-02-12 07:25:29 -05:00
|
|
|
const markdown = `Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`;
|
|
|
|
const fileURL = 'file.md';
|
|
|
|
|
|
|
|
const { code, metadata } = await processor.render(markdown, { fileURL });
|
|
|
|
|
|
|
|
assert.equal(
|
2024-01-17 08:14:53 -05:00
|
|
|
code,
|
2024-02-12 07:25:29 -05:00
|
|
|
'<p>Hello <img __ASTRO_IMAGE_="{"src":"./img.webp","alt":"image ref","index":0}"></p>'
|
|
|
|
);
|
|
|
|
|
2024-02-16 06:41:16 -05:00
|
|
|
assert.deepEqual(Array.from(metadata.imagePaths), ['./img.webp']);
|
2024-01-17 08:14:53 -05:00
|
|
|
});
|
2023-09-13 10:29:39 -05:00
|
|
|
});
|