#Astro component in remark plugin

11 messages · Page 1 of 1 (latest)

violet tinsel
#

I would like to create a remark plugin that can replace some tags like code or image with an Astro component. The remark plugins can be configured to be used in astro.config.mjs, but then how do I inject the Astro component in the transformer function ? how do I create a node.type and a node.value to be later interpreted as an Astro component ?

naive harness
#

In Markdown you kinda can't, in MDX you can though

timid vine
#

or mdoc

violet tinsel
violet tinsel
# timid vine *or mdoc*

my goal is to rehype existing .md database and augment it with features. While mdx can do that to some extent with multiple dangerous fails that do not happen with .md, with mdoc it's out of scope as it does not even support html in the markdown.
my goal is to stick to the most commonly used markdown to have it visible in vscode and github while enhanced in astro website.

#

so we can think of the markdown for me as some sort of 'cms provider' that I want to render in Astro with Astro features.

shadow crest
# violet tinsel my goal is to rehype existing .md database and augment it with features. While m...

mdoc does not even support html
With Markdoc it's theoretically possible to allow HTML tags, however it would involve changes to the Markdoc tokenizer and I'm not sure how easy it would be to do for the Markdoc included with <@&1055234544183287879>/markdoc

You can see the workaround here https://github.com/markdoc/markdoc/issues/10#issuecomment-1492560830

GitHub

The commonMark spec describes how HTML blocks and Raw HTML should be treated: 4.6 HTML blocks An HTML block is a group of lines that is treated as raw HTML (and will not be escaped in HTML output)....

#

All in all, the thing you have described is exactly what Markdoc is built for. For example you could write a Markdoc config that would hook up to built in markdown elements and render them in some way using astro components

timid vigil
#

As Erika noted, this only works with MDX because regular .md doesn’t know how to render components.

violet tinsel
# shadow crest All in all, the thing you have described is exactly what Markdoc is built for. F...

thank you for this valuable hint, this actually creates a new hope for the modern web (.md with Astro components)
I'll be following up on this, I started an mdoc astro example https://github.com/MicroWebStacks/astro-examples#31_collections-markdoc that I'll try to update.
between hacking mdx and hacking mdoc to achieve what I want, I prefer the mdoc path as it is more consistent with the content vs framework components separation concept. I hope that mdoc community gets wise enough to kepp .md and gfm compatibilit in mind.
the biggest pain I had with .mdx is that it does not support 'silent fail' which is crucial for trusted but unmanaged content deployment. with mdx the whole website build fails, and I have to edit the content with a patch to make it build again. That shows that mdx is a developper file format and not a content creator file format.