The Astro Markdown pipeline turns a .md file into HTML in five stages: read and validate the frontmatter, parse the body into a Markdown syntax tree (mdast), transform it into an HTML tree (hast), add Astro’s built-in features such as heading IDs, syntax highlighting and image optimisation, then compile the result into an Astro component you render with <Content />. In Astro 7 the default processor for those middle stages is Sätteri, a Rust-backed Markdown engine, and you can switch to the classic remark and rehype pipeline with unified().
Knowing where each step happens tells you where to hook in: schema problems belong to content collections, syntax extensions to mdast plugins, output tweaks to hast plugins, and layout to your Astro components.
Key Takeaways
- Markdown goes file, frontmatter, mdast, hast, HTML, then an Astro component.
- Sätteri is Astro 7’s default processor;
unified()from@astrojs/markdown-remarkkeeps remark and rehype plugins working.- Plugins now go on
markdown.processor, not on the deprecatedmarkdown.remarkPluginsandrehypePlugins.- Astro adds heading IDs, Shiki highlighting, smart punctuation, GFM and image handling on top of the processor.
- MDX inherits plugins from
markdown.processor, so one configuration covers both formats.
Stage 1: the file and its frontmatter
Markdown reaches Astro in two ways: as a file in src/pages/ (which becomes a route) or, far more commonly, as an entry in a content collection loaded with glob(). Either way, the YAML or TOML frontmatter between the --- fences is parsed first.
In a collection, that frontmatter is validated against your schema before any Markdown is processed. A missing field or wrong type fails the build with a message naming the file and the field:
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const blog = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/blog' }),
schema: z.object({
title: z.string(),
pubDate: z.coerce.date(),
draft: z.boolean().default(false),
}),
});
export const collections = { blog };
Validation happens before the body is rendered, so a bad field never produces half-built HTML. You get the rendered body later by calling render(entry), which is why that is a separate, async step. Our content collections guide covers loaders and schemas in detail.
Stage 2: parsing to mdast
The processor parses the Markdown body into mdast, a syntax tree where each heading, paragraph, list, code block and link is a node. GitHub-flavoured Markdown is on by default, so tables, task lists, strikethrough, autolinks and footnotes are recognised here.
This is the stage for syntax changes: anything that changes what the Markdown means. Directives (:::note), math, wikilinks and custom shortcodes are all mdast-level concerns. With Sätteri, several of those are built-in features you switch on rather than plugins you install:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import { satteri } from '@astrojs/markdown-satteri';
export default defineConfig({
markdown: {
processor: satteri({
features: {
directive: true,
math: true,
headingAttributes: true,
definitionList: true,
},
}),
},
});
Each of those defaults to off. GFM and frontmatter default to on, and Astro turns smart punctuation on by default.
Stage 3: mdast to hast
Next the Markdown tree is converted to hast, a tree of HTML elements. A heading node becomes an h2 element, a code node becomes pre > code, a footnote reference becomes a link with an ID. Raw HTML you wrote inside Markdown is carried through as raw nodes by default.
This is the stage for output changes: attributes on links, wrappers around tables, classes on images. A hast plugin for Sätteri is an object with a visitor per node type. This one adds target and rel to external links:
// src/markdown/external-links.mjs
import { defineHastPlugin } from 'satteri';
export const externalLinks = defineHastPlugin({
name: 'external-links',
element: {
filter: ['a'],
visit(node, ctx) {
const href = String(node.properties?.href ?? '');
if (/^https?:\/\//.test(href)) {
ctx.setProperty(node, 'target', '_blank');
ctx.setProperty(node, 'rel', 'noopener noreferrer');
}
},
},
});
// astro.config.mjs
import { defineConfig } from 'astro/config';
import { satteri } from '@astrojs/markdown-satteri';
import { externalLinks } from './src/markdown/external-links.mjs';
export default defineConfig({
markdown: {
processor: satteri({ hastPlugins: [externalLinks] }),
},
});
The filter: ['a'] line matters for speed: Sätteri filters nodes in Rust and only hands matching elements to your JavaScript visitor.
Stage 4: Astro’s built-in features
On top of the processor, Astro adds the features every content site needs:
| Feature | What it does | Control |
|---|---|---|
| Heading IDs | Adds slugified id attributes to headings and collects them for headings |
Always on; read via render() |
| Syntax highlighting | Highlights fenced code with Shiki (default github-dark) or Prism |
markdown.syntaxHighlight, markdown.shikiConfig |
| Images | Finds local ![]() images and optimises them through astro:assets |
Automatic for relative paths |
| Smart punctuation | Curly quotes, dashes and ellipses | smartPunctuation (Sätteri) or smartypants (unified) |
| GFM | Tables, task lists, footnotes, autolinks | features.gfm or gfm |
Image handling is worth understanding. When the processor sees , Astro marks the image, resolves the file relative to the Markdown file, and later replaces it with an optimised image and correct dimensions. Images in public/ are left as plain <img> tags, and remote images follow your image.domains and image.remotePatterns settings.
Syntax highlighting runs as a hast step too, which is why markdown.shikiConfig still applies whichever processor you use. Our guide to Shiki syntax highlighting in Astro covers themes and transformers.
Stage 5: compiling to a component
Finally the HTML is wrapped in an Astro component. For a collection entry you get it from render(), along with the headings and any frontmatter that plugins added:
---
// src/pages/blog/[id].astro
import { getCollection, render } from 'astro:content';
export async function getStaticPaths() {
const posts = await getCollection('blog', ({ data }) => !data.draft);
return posts.map((post) => ({ params: { id: post.id }, props: { post } }));
}
const { post } = Astro.props;
const { Content, headings } = await render(post);
const toc = headings.filter((h) => h.depth <= 3);
---
<article>
<h1>{post.data.title}</h1>
<nav aria-label="On this page">
<ul>{toc.map((h) => <li><a href={`#${h.slug}`}>{h.text}</a></li>)}</ul>
</nav>
<Content />
</article>
Each heading object has depth, slug and text, which is all you need for a table of contents. Because <Content /> is a component, the HTML is placed into your layout at build time and ships no JavaScript. The table of contents tip builds a nested version.
Keeping remark and rehype plugins: unified()
If you depend on plugins from the remark and rehype ecosystem, such as remark-toc, rehype-autolink-headings or rehype-katex, switch the processor to unified(). It is the pipeline Astro used before Sätteri and accepts the familiar options:
# Terminal
npm install @astrojs/markdown-remark rehype-autolink-headings
// astro.config.mjs
import { defineConfig } from 'astro/config';
import { unified } from '@astrojs/markdown-remark';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
export default defineConfig({
markdown: {
processor: unified({
rehypePlugins: [[rehypeAutolinkHeadings, { behavior: 'append' }]],
smartypants: true,
gfm: true,
}),
},
});
The older top-level markdown.remarkPlugins, markdown.rehypePlugins, markdown.gfm, markdown.smartypants and markdown.remarkRehype options still work in Astro 7 but are deprecated and will be removed in a future major version. Move them into the processor now. The same goes for remarkPlugins passed to the MDX integration: MDX inherits plugins from markdown.processor, so configure them once there.
Choosing a processor
| Sätteri (default) | unified() | |
|---|---|---|
| Install | Built in | @astrojs/markdown-remark |
| Parsing | Rust, called from JavaScript | JavaScript |
| Plugins | Sätteri mdast and hast plugins | remark and rehype ecosystem |
| Common extensions | Built-in feature flags (math, directives, wikilinks) | Separate plugins |
| Best for | Most sites, large content sets | Projects relying on specific remark or rehype plugins |
Sätteri’s mdast and hast trees use the same shapes as unified’s, so porting a small plugin is usually a matter of changing the wrapper rather than the logic. Large ecosystems, such as a specific math renderer you rely on, are the main reason to stay on unified. The official Markdown guide describes both processors and their options.
Where to fix common problems
- Build fails on a field → stage 1. Fix the frontmatter or the schema.
- Syntax not recognised (callouts, math) → stage 2. Enable a Sätteri feature or add an mdast or remark plugin.
- Wrong HTML attributes → stage 3. Add a hast or rehype plugin.
- Code colours or image sizes wrong → stage 4. Adjust
shikiConfigor check the image path. - Layout and styling → stage 5. Change the page or layout component, or style the rendered HTML with a prose stylesheet.
Most Astro themes, including ours, keep posts as Markdown or MDX in collections, so these hooks apply directly; the content docs show where a theme’s entries live.
FAQ
What Markdown parser does Astro use?
Astro 7 uses Sätteri, a Markdown engine that parses in Rust and runs plugins in JavaScript, as its default processor. You can switch to the remark and rehype based pipeline by installing @astrojs/markdown-remark and setting markdown.processor to unified().
Do remark plugins still work in Astro 7?
Yes, through the unified() processor. Pass them as unified({ remarkPlugins: [...] }) in markdown.processor. The top-level markdown.remarkPlugins option still works but is deprecated.
How do I add IDs to headings in Astro Markdown?
Astro adds slugified IDs to every heading automatically. You can read them from the headings array returned by render(). With Sätteri’s headingAttributes feature you can also set a custom ID in the Markdown itself.
Does MDX use the same pipeline as Markdown?
MDX has its own integration, @astrojs/mdx, because it also compiles JSX and JavaScript expressions. It inherits plugins and settings from markdown.processor, so most configuration is shared between .md and .mdx files.
Why is my Markdown image not optimised?
Only local images referenced with a relative path from the Markdown file are processed by astro:assets. Images in public/ are output as plain <img> tags, and remote images are only processed if your image.domains or image.remotePatterns settings allow them. Move the file next to your content and use a relative path such as ./image.png.