Add a Sätteri tab in the remark/rehype recipes - #14277
Conversation
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
|
Preview deployment ✅ Deployment complete!
|
| import getReadingTime from 'reading-time'; | ||
| import { defineMdastPlugin, type MdastNode } from 'satteri'; | ||
|
|
||
| const findRoot = ( |
There was a problem hiding this comment.
This is verbose compared to the remark version but, AFAIK, this is the best way in Sätteri; I've done the same thing when porting my website. Parsing ctx.source instead seems to work with Markdown files but this is not reliable with MDX (components, custom plugins).
|
|
||
| export const mdastReadingTimePlugin = defineMdastPlugin({ | ||
| name: "mdast-reading-time", | ||
| text(node, context) { |
There was a problem hiding this comment.
Not sure if there is something better than the text() visitor here. Because it runs multiple times for the same file, we need to check if the frontmatter property is set to return early.
| import MarkdownProcessorTabs from '~/components/tabs/MarkdownProcessorTabs.astro'; | ||
|
|
||
| Using a rehype plugin, you can identify and modify links in your Markdown files that point to external sites. This example adds icons to the end of each external link, so that visitors will know they are leaving your site. | ||
| Using a Markdown plugin, you can identify and modify links in your Markdown files that point to external sites. This example adds an icon to the end of each external link, so that visitors will know they are leaving your site. |
There was a problem hiding this comment.
Curious. Before we initially said rehype, which are the HTML plugins, and not remark, which are the Markdown plugins.
Should the new copyright be generic?
There was a problem hiding this comment.
Right, remark and rehype do not run with the same context, but I think this is our generic term at the moment:
- remark (unified) / mdast (Sätteri): plugins to control how Markdown files are parsed
- rehype (unified) / hast (Sätteri): plugins to control the HTML output of Markdown files
- unified plugins / Sätteri plugins: Markdown plugins
But I see what you mean; it might be oversimplified and could be confusing for some... Maybe "Markdown processor plugins" would be better to talk of both. But, I'm not sure what to use to distinguish between the two.
I mean, I don't think I've ever seen "HTML plugins" being used to refer to "rehype plugins". Even before Sätteri, "hast plugins" would have been more meaningful to me as rehype plugins work on a hast tree.
I was looking what others use:
- Docusaurus uses "MDX plugins" to gather remark and rehype plugins
- VitePress uses "Markdown extensions", but they use MarkdownIT so I'm not sure there is a concept like remark/rehype with it.
So, yeah, not sure what we should do here. 🤔
There was a problem hiding this comment.
Consider also that I come from a place where I learnt about the different between remark and rehype very recently (during the Satteri migration), and unified was meant join them together. I don't know the level of knowledge of the audience of the guide, but consider that there people like me that don't know anything about this ecosystem (or very little).
There was a problem hiding this comment.
Oh yeah, I'm totally biased here (I also use nlcst so... 😄 ). I think this is a good call and not only for the recipes, but the Markdown guide as well! I might create a Discord thread tomorrow for some brainstorming, unless I have a flash of inspiration overnight...
What I have so far... (spoiler: not much)
For remark/mdast and rehype/hast:
- "Markdown AST plugins" and "HTML AST plugins"
- "Markdown tree plugins" and "HTML tree plugins"
- "MDAST plugins" and "HAST plugins" (well... seems accurate to me, but then it might be confusing because that's how Sätteri call them, not unified)
- "remark and mdast plugins" and "rehype and hast plugins" 😅
As umbrella, for any plugin (this could include recma as well):
- Markdown processor plugins (would that be as confusing as "Markdown plugins" given this includes rehype/hast?)
- Processor plugins (as long as this is only used in Markdown context, this could work)
- Syntax tree plugins
- AST plugins
There was a problem hiding this comment.
So I haven't forgotten that, and I'm not sure I had a "flash of inspiration" 😆 but, I'm trying a different approach: update the Markdown guide first to perhaps find a better idea for a name. (#14297, WIP!) We have at least one outdated section and we'll need to update "Markdown plugins" there too...
I probably won't have much time to dedicate to it tomorrow though, so I'll continue next week.
Description (required)
Since Astro 7, Sätteri is the default Markdown processor, but our recipes were still using remark/rehype. This adds Sätteri/Unified tabs to them!
external-links.mdx:<Steps />nested inside<Tabs />as the content is different enoughmodified-time.mdxandreading-time.mdx:<Tabs />nested inside<Steps />as the content is pretty similar (a bit annoying for the packages to install though)syncKeyfor Unified/Sätteri, so I added a new<MarkdownProcessorTabs />component to ensure this remains in sync. (AD² says "Other custom components may be added over time." so I don't think we need a PR there)If you want to check/play with the plugins:
Note that git is not available on Stackblitz, so you'll need to download the repro, init Git, and make an initial commit.
In addition, I updated a few other things:
external-links.mdx: Removes the callout at the end as the statement is wrong.rehype-external-linksdoes not use the CSScontentproperty but a<span />to inject the content (see https://www.npmjs.com/package/rehype-external-links#fields). So, the icon is in the accessibility tree. Now, I agree this is not the best for accessibility but it doesn't seem like we have control on the<span>(e.g. to setaria-hidden: true).modified-time.mdxandreading-time.mdx, continuing my series on fixing code snippets issues:<head>...</head>is formatted to<head></head>...so I added some content in there instead.<meta charset="utf-8" / >is expected since v5