-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat: A native pipeline for content #16149
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
base: next
Are you sure you want to change the base?
Changes from 29 commits
9b81609
bcce353
f6b7872
4d0a4c4
5e54e36
d9a0f66
8a4a7ef
838a475
c204fd0
ac179d1
d74c82e
a03e004
857f322
e9e0a6e
d15120a
a1e593a
a108c43
8857e17
1fbfd6e
a7fa4ad
d26ddd4
f8e5d19
8ab9eac
74c5832
7853a2f
209b79b
7c5521f
0afe01f
6827983
1f15ab6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| '@astrojs/mdx': major | ||
| --- | ||
|
|
||
| `@astrojs/mdx` now picks up the processor from `markdown.processor` automatically, so a single Sätteri or unified configuration drives both `.md` and `.mdx` files. To run `.mdx` files through a different processor (or the same processor with different options) than your `.md` files, pass the `processor` option to the integration: | ||
|
|
||
| ```js | ||
| // astro.config.mjs | ||
| import { defineConfig, satteri } from 'astro/config'; | ||
| import mdx from '@astrojs/mdx'; | ||
| import { unified } from '@astrojs/markdown-remark'; | ||
|
|
||
| export default defineConfig({ | ||
| markdown: { processor: satteri() }, | ||
| integrations: [mdx({ processor: unified({ remarkPlugins: [/* ... */] }) })], | ||
| }); | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --- | ||
| 'astro': major | ||
| '@astrojs/markdown-remark': major | ||
| '@astrojs/markdown-satteri': major | ||
| --- | ||
|
|
||
| Adds a `markdown.processor` config option to configure the Markdown processor to use. By default, [Sätteri](https://github.com/bruits/satteri) a fast Rust-based Markdown/MDX compiler is used. Both `.md` and `.mdx` files now render through Sätteri. | ||
|
|
||
| To pass Sätteri plugins or enable additional parser features, use the `satteri()` explicitely: | ||
|
|
||
| ```js | ||
| // astro.config.mjs | ||
| import { defineConfig, satteri } from 'astro/config'; | ||
|
|
||
| export default defineConfig({ | ||
| markdown: { | ||
| processor: satteri({ | ||
| hastPlugins: [myPlugin], | ||
| features: { directive: true, smartPunctuation: false }, | ||
| }), | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| To keep using your existing remark/rehype plugins, install `@astrojs/markdown-remark` into your project and use the `unified` export: | ||
|
|
||
| ```sh | ||
| pnpm add @astrojs/markdown-remark | ||
| ``` | ||
|
|
||
| ```js | ||
| // astro.config.mjs | ||
| import { defineConfig } from 'astro/config'; | ||
| import { unified } from '@astrojs/markdown-remark'; | ||
| import remarkToc from 'remark-toc'; | ||
|
|
||
| export default defineConfig({ | ||
| markdown: { | ||
| processor: unified({ remarkPlugins: [remarkToc] }), | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| The top-level `markdown.remarkPlugins`, `markdown.rehypePlugins`, and `markdown.remarkRehype` options are deprecated. They'll continue to work when `@astrojs/markdown-remark` is installed for now, but this will be removed in the next major. | ||
|
|
||
| The top-level `markdown.gfm` and `markdown.smartypants` options are also deprecated. Move them onto your processor instead — `satteri({ features: { gfm: false, smartPunctuation: false } })`, or `unified({ gfm: false, smartypants: false })`: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In theory, those two options could be fully removed and we could ask users to manually install the Remark plugins, but I figured for a better migration story right now we can just support them in the processor itself. It's not relevant for Sätteri because it's supported natively there. |
||
|
|
||
| ```js | ||
| // astro.config.mjs | ||
| import { defineConfig } from 'astro/config'; | ||
| import { unified } from '@astrojs/markdown-remark'; | ||
|
|
||
| export default defineConfig({ | ||
| markdown: { | ||
| processor: unified({ gfm: false, smartypants: false }), | ||
| }, | ||
| }); | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import type { MarkdownHeading } from '@astrojs/markdown-remark'; | ||
| import type { MarkdownHeading } from '@astrojs/internal-helpers/markdown'; | ||
| import { escape } from 'html-escaper'; | ||
| import { Traverse } from 'neotraverse/modern'; | ||
| import * as z from 'zod/v4'; | ||
|
|
@@ -461,7 +461,9 @@ async function updateImageReferencesInBody(html: string, fileName: string) { | |
| // function because getImage is async. | ||
| for (const [_full, imagePath] of html.matchAll(CONTENT_LAYER_IMAGE_REGEX)) { | ||
| try { | ||
| const decodedImagePath = JSON.parse(imagePath.replaceAll('"', '"')); | ||
| const decodedImagePath = JSON.parse( | ||
| imagePath.replace(/&(?:#x22|quot);/g, '"').replace(/&(?:#x27|apos);/g, "'"), | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit of a remark quirk, it uses numeric character references only, but a lot of Markdown processors (and Sätteri) I've noticed tend to use named references instead. Either way, both are allowed in the Markdown spec.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment on what this is doing? |
||
| ); | ||
|
|
||
| let image: GetImageResult; | ||
| if (URL.canParse(decodedImagePath.src)) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing a little weird here, if you wanted to use unified for both, would that mean you'd do:
Or would you keep the processor in a variable and reference it in both places? Do they need to share state?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's the same as the current options, MDX inherits the options from
markdownby default: https://docs.astro.build/en/guides/integrations-guide/mdx/#extendmarkdownconfigIt's a weird behavior of MDX in my opinion... but in line with what we currently have, at least. They don't need to share state, the things that could be shared are always module-level (e.g. Shiki)