-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(markdown): Add support for
imageReference
paths when collectin…
…g images (#8475)
- Loading branch information
Showing
6 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/markdown-remark': minor | ||
--- | ||
|
||
feat(markdown): Add support for `imageReference` paths when collecting images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/markdown/remark/test/remark-collect-images.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { renderMarkdown } from '../dist/index.js'; | ||
import { mockRenderMarkdownParams } from './test-utils.js'; | ||
import chai from 'chai'; | ||
|
||
describe('collect images', () => { | ||
it('should collect inline image paths', async () => { | ||
const { code, vfile } = await renderMarkdown( | ||
`Hello ![inline image url](./img.png)`, | ||
mockRenderMarkdownParams | ||
); | ||
|
||
chai | ||
.expect(code) | ||
.to.equal('<p>Hello <img alt="inline image url" __ASTRO_IMAGE_="./img.png"></p>'); | ||
|
||
chai.expect(Array.from(vfile.data.imagePaths)).to.deep.equal(['./img.png']); | ||
}); | ||
|
||
it('should add image paths from definition', async () => { | ||
const { code, vfile } = await renderMarkdown( | ||
`Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`, | ||
mockRenderMarkdownParams | ||
); | ||
|
||
chai.expect(code).to.equal('<p>Hello <img alt="image ref" __ASTRO_IMAGE_="./img.webp"></p>'); | ||
chai.expect(Array.from(vfile.data.imagePaths)).to.deep.equal(['./img.webp']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const mockRenderMarkdownParams = { | ||
fileURL: 'file.md', | ||
contentDir: new URL('file:///src/content/'), | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.