2026-08-30
每日一文 · 长文精读

Astro Introduces Sätteri: a Rust-Powered Markdown and Mdx Processor with up to 60% Faster Builds

Astro 推出 Sätteri:一个由 Rust 驱动的 Markdown 和 MDX 处理器,构建速度提升高达 60%

作者:Daniel Curtis · InfoQ 原文

摘要:Astro 团队发布了 Sätteri,一个基于 Rust 的高性能 Markdown 和 MDX 处理器,现已作为 Astro 7.0 的核心依赖,带来最高 60% 的构建速度提升。它使用 pulldown-cmark 和 Oxc 进行解析,支持 JavaScript 插件,原生实现了 GitHub 风格 Markdown、数学公式等许多原本需要插件的功能。迁移时需注意不运行 remark/rehype 插件,但可通过 @astrojs/markdown-remark 继续使用 unified 生态。Sätteri 开源,可通过 npm 和 crates.io 获取。

Sätteri, a new high-performance Markdown and MDX processor for the JavaScript ecosystem, has been introduced by the Astro team and now sits at the heart of the recently released Astro 7.0.
Sätteri 是一个面向 JavaScript 生态的高性能 Markdown 和 MDX 处理器,由 Astro 团队推出,现已成为刚发布的 Astro 7.0 的核心组件。
Built in Rust and maintained separately by Astro core contributor Erika under the Bruits collective, Sätteri lives outside the Astro organisation but has become a core dependency of the framework, where the team says it contributes up to 60% faster builds.
Sätteri 用 Rust 编写,由 Astro 核心贡献者 Erika 在 Bruits 组织下独立维护,它独立于 Astro 组织,但已成为该框架的核心依赖,团队称其可将构建速度提升高达 60%。
Sätteri puts flexible JavaScript plugins on top of a fast Rust Markdown and MDX engine, using pulldown-cmark for CommonMark parsing and Oxc for MDX expression parsing.
Sätteri 在快速的 Rust Markdown 和 MDX 引擎之上提供了灵活的 JavaScript 插件,使用 pulldown-cmark 进行 CommonMark 解析,使用 Oxc 进行 MDX 表达式解析。
It ships platform-specific native binaries with a WASM fallback, the same approach Astro uses for its new Rust compiler, and it can be tried live in the browser via WebAssembly.
它提供了平台特定的原生二进制文件,并带有 WASM 回退方案,与 Astro 用于其新 Rust 编译器的方法相同,并且可以通过 WebAssembly 在浏览器中实时试用。
The processor first appeared as an opt-in @astrojs/markdown-satteri package in Astro 6.4, and Astro 7 promotes it to the default.
该处理器最初作为可选包 @astrojs/markdown-satteri 出现在 Astro 6.4 中,而 Astro 7 将其提升为默认选项。
The headline benefit is speed: switching the Astro and Cloudflare documentation sites to Sätteri shaved over a minute off each build, and overall Astro 7 builds improved by 15 to 61%.
最大的好处是速度:将 Astro 和 Cloudflare 文档站点切换到 Sätteri 后,每次构建节省了一分多钟,总体 Astro 7 构建提升了 15% 到 61%。
Much of that gain comes from moving parsing out of JavaScript, replacing the unified pipeline of remark, rehype and a long tail of dependencies that previously ran plugin after plugin over the full syntax tree.
大部分提升来自于将解析移出 JavaScript,取代了之前在整个语法树上逐个运行插件的 unified 管道(包括 remark、rehype 以及大量依赖)。
Speed is not the only change.
速度并非唯一的变化。
Sätteri implements natively many features that previously required separate plugins, including GitHub Flavored Markdown, smart punctuation, container directives, math, frontmatter, superscript, subscript and wikilinks.
Sätteri 原生实现了许多以前需要单独插件的功能,包括 GitHub 风格 Markdown、智能标点、容器指令、数学公式、frontmatter、上标、下标和维基链接。
Optional features are enabled through the processor config.
可选功能通过处理器配置启用。
On Hacker News, one developer expressed their disappointment:
在 Hacker News 上,一位开发者表达了他们的失望:
"Switch from widely supported unified/rehype to own rehype-incompatible markdown tooling just for build time speed improvement is quite upsetting"
“从广泛支持的 unified/rehype 转向自己专用的、不兼容 rehype 的 Markdown 工具,仅仅为了加快构建速度,这相当令人失望”
"Good that they added a tool to keep using rehype, but Im unsure that it will last"
“还好他们添加了一个工具来继续使用 rehype,但我不确定它能持续多久”
Which prompted a reply from Erika, the author of the library:
这引发了该库作者 Erika 的回复:
"We don't intend on removing support for the unified ecosystem, we on purpose made the Markdown processing pipeline pluggable so that it was possible for both to exists!"
“我们不打算移除对 unified 生态的支持,我们特意让 Markdown 处理管道可插拔,以便两者可以共存!”
"The vast majority of our users don't use any sort of unified plugins, so a pipeline that's faster (and about 100 deps leaner) felt like a better default."
“我们的绝大多数用户根本不使用任何 unified 插件,因此一个更快(且依赖减少约 100 个)的管道作为默认选项感觉更合适。”
Another commenter asked:
另一位评论者问道:
"How does Satteri compare to a standard library like marked (https://github.com/markedjs/marked)?"
“Sätteri 与 marked(https://github.com/markedjs/marked)等标准库相比如何?”
To which Erika also replied:
Erika 也对此进行了回复:
"It depends in what regards you mean, I have some benchmarks here if you'd like to take a look at those: https://github.com/Princesseuh/web-markdown-benchmark"
“这取决于你指的是哪个方面,我这里有基准测试,你可以看看:https://github.com/Princesseuh/web-markdown-benchmark”
"The TL;DR is that marked is very light, but a bit on the slower side compared to Sätteri and markdown-it (and its forks)."
“长话短说,marked 非常轻量,但相比 Sätteri 和 markdown-it(及其分支)稍慢一些。”
"I'm not sure how friendly the extensibility is, but Sätteri re-use the same AST format as the unified ecosystem, which might feel more friendly."
“我不确定可扩展性如何,但 Sätteri 复用了与 unified 生态相同的 AST 格式,这可能更容易上手。”
"Both good options, though!"
“不过两者都是不错的选择!”
The main migration caveat is that Sätteri does not run remark or rehype plugins.
迁移的主要注意事项是 Sätteri 不运行 remark 或 rehype 插件。
The Astro v7 upgrade guide advises that projects without plugins need no changes, while those depending on plugins can port them to Sätteri MDAST or HAST plugins or stay on unified by installing @astrojs/markdown-remark.
Astro v7 升级指南建议,没有插件的项目无需更改,而依赖插件的项目可以将其移植为 Sätteri MDAST 或 HAST 插件,或通过安装 @astrojs/markdown-remark 继续使用 unified。
Upgrades are handled with npx @astrojs/upgrade.
升级通过 npx @astrojs/upgrade 处理。
Sätteri is not alone in chasing native Markdown speed.
Sätteri 并非唯一追求原生 Markdown 速度的处理器。
Bun.markdown, written in Zig, has reported comparable gains but lacks a plugin system, leaving Sätteri's reuse of the unified AST format as a distinguishing feature.
用 Zig 编写的 Bun.markdown 也报告了类似的提升,但缺乏插件系统,这使得 Sätteri 复用 unified AST 格式成为一个独特的特点。
Sätteri is open source and available via npm and crates.io.
Sätteri 是开源的,可通过 npm 和 crates.io 获取。

阅读理解

1. What is the primary benefit of using Sätteri according to the article?

温故复习 →每日一句 →