withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
43.84k stars 2.28k forks source link

Handle encoded image paths in markdown #11310

Closed bluwy closed 1 week ago

bluwy commented 1 week ago

Changes

fix https://github.com/withastro/astro/issues/11291

The markdown vfile data.imagePaths now contains decoded paths instead of possibly-encoded paths. I'm not sure if this is ideal/intentional for the option itself, but this top-level change helps align all downstream usage:

  1. Printing decoded paths in the imports allow Vite to properly resolve assets (Also a Vite bug)

https://github.com/withastro/astro/blob/93d068a855fe0aafb822950ad86fe54ddc041f84/packages/astro/src/vite-plugin-markdown/images.ts#L6-L8

  1. MDX rehypeImageToComponent currently compares with decoded paths, the generated imports are also decoded:

https://github.com/withastro/astro/blob/93d068a855fe0aafb822950ad86fe54ddc041f84/packages/integrations/mdx/src/rehype-images-to-component.ts#L84-L86

  1. rehype-images is also comparing with decoded paths:

https://github.com/withastro/astro/blob/93d068a855fe0aafb822950ad86fe54ddc041f84/packages/markdown/remark/src/rehype-images.ts#L14-L16

  1. Encoded paths also messes with this regex generation (that I don't complete understand yet):

https://github.com/withastro/astro/blob/93d068a855fe0aafb822950ad86fe54ddc041f84/packages/astro/src/vite-plugin-markdown/images.ts#L12-L20


So with the above discoveries, I made this PR change instead of keeping imagePaths encoded only.

Testing

Added new tests

Docs

n/a. bug fix.

changeset-bot[bot] commented 1 week ago

🦋 Changeset detected

Latest commit: 93d068a855fe0aafb822950ad86fe54ddc041f84

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR