#Regular MD with Components? (not MDX)

11 messages · Page 1 of 1 (latest)

tall pine
#

I need markdown, components and attributes. I don't need MDX, especially since MDX is incompatible with attributes (like rehype-attrs) because it hijacks the curly braces. Is there any way to use components in regular MD files in order to be able to use powerful MD plugins like rehype-attrs? I use attributes so much with MD, I wonder why it's not part of the base spec.

south raptorBOT
#

Hi @tall pine. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the extracts, it seems that using components in regular Markdown files is a topic that has been discussed within the Astro community, but it's not currently supported.

In the Github Issue 364 (https://github.com/withastro/astro/issues/364), it was mentioned that initially Astro supported MDX in .md files, but it had some issues and didn't support everything you could do in a .astro file. The idea of bringing back component usage within .md files was considered, but it seems it hasn't been implemented yet.

In the Github Issue 6730 (https://github.com/withastro/astro/issues/6730), a member stated that you cannot use components in Markdown and that there's currently no way to resize images in Markdown when using Markdown syntax.

In the Github Issue 8311 (https://github.com/withastro/astro/issues/8311), it was mentioned that in MDX, img tags are replaced with a component using rehype, but user components are not respected at this time for that.

While Astro does support using custom components in MDX files as mentioned in the Astro documentation (https://docs.astro.build/en/guides/markdown-content/), it seems that this feature is not available for regular Markdown files.

It's worth noting that the Astro community is actively discussing and considering ways to simplify and enhance the usage of components in Markdown, so this might change in the future.

For now, if you need to use components with Markdown, you might have to use MDX or consider other workarounds.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@tall pine kapa.ai is still learning and improving, please let us know how it did by reacting below

tall pine
#

@south raptor is there any solution for using an attributes plugin (like rehype-attr or remark-attr) in MDX?

south raptorBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Based on the information provided in the extracts, it seems that Astro supports adding third-party remark and rehype plugins for Markdown and MDX. These plugins allow you to extend your Markdown with new capabilities. However, there is no specific mention of using an attributes plugin like rehype-attr or remark-attr in MDX.

Here is an example of how to apply remark and rehype plugins to both Markdown and MDX files in Astro:

import { defineConfig } from 'astro/config';
import remarkToc from 'remark-toc';
import { rehypeAccessibleEmojis } from 'rehype-accessible-emojis';

export default defineConfig({
  markdown: { 
    // Applied to .md and .mdx files 
    remarkPlugins: [remarkToc],
    rehypePlugins: [rehypeAccessibleEmojis],
  },
});

In this example, remark-toc and rehype-accessible-emojis plugins are applied to both Markdown and MDX files. You can replace these with your desired plugins.

However, it's important to note that MDX does not support passing remark and rehype plugins as a string. You should install, import, and apply the plugin function instead (source (https://docs.astro.build/en/guides/integrations-guide/mdx/)).

Please refer to each plugin’s own README for specific installation instructions. If you want to use an attributes plugin like rehype-attr or remark-attr, you would need to install and import them similarly, then add them to the remarkPlugins or rehypePlugins array in your Astro configuration.

Remember to always test your configuration changes to ensure they work as expected.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@tall pine kapa.ai is still learning and improving, please let us know how it did by reacting below

tall pine
#

@south raptor Is there any compatible attr plugin that works with Astro MDX?

south raptorBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Based on the information provided in the extracts, there is no specific mention of a compatible attributes plugin that works with Astro MDX. Astro does support adding third-party remark and rehype plugins for Markdown and MDX, but the specific use of an attributes plugin like rehype-attr or remark-attr is not explicitly mentioned.

You can try to use these plugins in a similar way as other plugins are used in Astro. However, it's important to note that the compatibility and functionality might vary, and you should always test your configuration changes to ensure they work as expected.

For more information on how to use plugins with Astro, you can refer to the Astro documentation (https://docs.astro.build/en/guides/integrations-guide/mdx/).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: