Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astro 3.0 Markdown/MDX auto image asset imports ignore Remark plugins #8311

Closed
1 task
i-bsd opened this issue Aug 30, 2023 · 12 comments · Fixed by #9753
Closed
1 task

Astro 3.0 Markdown/MDX auto image asset imports ignore Remark plugins #8311

i-bsd opened this issue Aug 30, 2023 · 12 comments · Fixed by #9753
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: assets Related to the Assets feature (scope) pkg: mdx Issues pertaining to `@astrojs/mdx` integration

Comments

@i-bsd
Copy link

i-bsd commented Aug 30, 2023

Astro info

Astro version            v3.0.3
Package manager          pnpm
Platform                 linux
Architecture             x64
Adapter                  Couldn't determine.
Integrations             @astrojs/mdx, @astrojs/partytown, @astrojs/prefetch, @astrojs/sitemap, @astrojs/react, @astrojs/svelte, client:click, astro-purgecss, astro-imagetools

What browser are you using?

Chrome

Describe the Bug

Upgraded to Astro 3.0.

Using Remark plugin remark-unwrap-images to remove parent <p> tags from images.

Because of the way Astro is now automatically processing relative path images in Markdown/MDX (e.g. ![alt](./filename.jpg)), the Remark plugin is ignored.

If I use /public/ folder images or remote images, there is no issue.

import remarkUnwrapImages from 'remark-unwrap-images';

...

integrations: [mdx(
    {
      remarkPlugins: [
        remarkUnwrapImages
      ]
    }
  )... ]

Can the automatic image asset import in Markdown/MDX be fixed to check for the existence of Remark plugins?

What's the expected result?

Outputted <img> should not be wrapped by <p> tags.

Astro's new automatic image asset imports in Markdown should take into account Remark plugins if they exist.

Link to Minimal Reproducible Example

https://github.com/i-bsd/astro-3-img-test

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Aug 30, 2023
@Princesseuh
Copy link
Member

Hmm, I'm not exactly sure how we would check for remark / rehype plugins existing for that. Nonetheless I think a way we could make this work for MDX at least would be a way to disable the rehype part that uses the Image component and instead have a remark plugin just adding the attributes to the node using getImage

I'm not sure why it doesn't work in vanilla Markdown however, there we just add attributes to the existing img tag.

@Princesseuh Princesseuh added - P3: minor bug An edge case that only affects very specific usage (priority) pkg: mdx Issues pertaining to `@astrojs/mdx` integration feat: assets Related to the Assets feature (scope) and removed needs triage Issue needs to be triaged labels Aug 31, 2023
@epsseniyer

This comment was marked as spam.

@i-bsd

This comment was marked as off-topic.

@epsseniyer

This comment was marked as spam.

@Princesseuh
Copy link
Member

@epsseniyer Please refrain from trying to help people in issues with AI tools. Your messages are all incorrect and spammy.

@epsseniyer
Copy link

No. I don't use any AI tool. If you want, you can go ask an AI, 'Is this your code?' I probably won't be there because I only use Google Translate. So, I'm just writing an English text that follows grammar rules, and I handle the formatting myself.

@i-bsd
Copy link
Author

i-bsd commented Aug 31, 2023

@epsseniyer Your comment was utterly irrelevant and unhelpful.

@epsseniyer
Copy link

Sorry then. @i-bsd

@i-bsd
Copy link
Author

i-bsd commented Sep 1, 2023

I'm not sure why it doesn't work in vanilla Markdown however, there we just add attributes to the existing img tag.

Does this also apply to MDX?

If I use custom components. E.g:

import Image from '@components/Image.astro'

const mdxComponents = {
	img: Image
}
---

<Page.Content components={mdxComponents} />

this <img> replacement is now ignored in Astro 3.0 also, just like the Remark plugins.

@Princesseuh
Copy link
Member

I'm not sure why it doesn't work in vanilla Markdown however, there we just add attributes to the existing img tag.

Does this also apply to MDX?

If I use custom components. E.g:

import Image from '@components/Image.astro'

const mdxComponents = {
	img: Image
}
---

<Page.Content components={mdxComponents} />

this <img> replacement is now ignored in Astro 3.0 also, just like the Remark plugins.

No, in MDX we replace the img tags with our component using rehype. It's a known issue that user components are not respected at this time for that.

In Markdown we can't do that, since well, you can't have components. So there the existing img tags just get updated attributes outside of the remark pipeline.

Markdoc works similarly to MDX. Many formats, many implementations, many problems, arf.

@Nickersoft
Copy link

Just ran into this problem myself – is there any plan to address this?

@just-andy
Copy link

I've tried using this plugin too

@florian-lefebvre florian-lefebvre linked a pull request Jan 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: assets Related to the Assets feature (scope) pkg: mdx Issues pertaining to `@astrojs/mdx` integration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants