r/javascript • • 4d ago

Your remark/rehype plugins don't run on Astro 7's Sätteri – drop-in ports

https://github.com/Ashish-CodeJourney/satteri-plugins

Astro 7 moved to Sätteri, a Rust Markdown engine. It's fast, but it has its own AST, so rehype-katex, rehype-slug, rehype-sanitize etc. stop working.

I ported the 10 most-used ones. Each is tested against the original plugin's output, so it's a swap, not a rewrite: slug, autolink-headings, katex, mathjax, sanitize, breaks, github, mdx-frontmatter, validate-links, citation.

The README also has a table of plugins you can just delete, because Sätteri has them built in (gfm, frontmatter, smartypants, directive…).

Live demo: https://satteri-plugins.js.org Repo: https://github.com/Ashish-CodeJourney/satteri-plugins

Which plugin is blocking your upgrade? I'll port the next most-requested one.

5 Upvotes

9 comments sorted by

1

u/rodriguez-cindy_6 4d ago

Output parity is a useful baseline; do the tests also cover custom plugin options and edge cases?

0

u/Thick_Jeweler_4018 4d ago

Yes, it convers all edge cases, the core behaviour is same as rehype

1

u/nganna6401 3d ago

Keeping parity fixtures tied to upstream versions would make it easier to see which behavior each port matches.

1

u/Thick_Jeweler_4018 3d ago

Yup, BTW are you using Astro for any of your projects ?

1

u/Discordbothost 2d ago

Since Sätteri is Rust and the plugins stay JS, is each port re-crossing the WASM/FFI boundary per node, or do you batch the whole AST across once? Curious about the perf story on big docs.

1

u/Thick_Jeweler_4018 2d ago

Good question. The ports don't walk the tree themselves — they use Sätteri's visitor API (defineHastPlugin with element: { filter: [...], visit }). The plugin declares which node types it cares about, and Sätteri only calls into JS for matching nodes. So satteri-slug only gets called for h1–h6, not for every text node or paragraph. Edits like ctx.setProperty go back as targeted mutations rather than a full JS copy of the tree.

1

u/jjohnson-13233 1d ago

How does this scale on large documents with many matching nodes? Do you have end-to-end timings for the JS callback path?

1

u/Thick_Jeweler_4018 1d ago

Good question, so I measured it instead of guessing. I timed plain Sätteri against Sätteri + satteri-slug on worst-case docs where every section is a heading + paragraph, so every heading triggers a JS callback.

Setup: satteri 0.11.5, Node 25, i7-10750H, median of 10 runs.

┌──────────┬──────────┬───────────────┬────────┐

│ Headings │ Doc size │ Sätteri alone │ + slug │

├──────────┼──────────┼───────────────┼────────┤

│ 1,000 │ 70 KB │ 1.0 ms │ 3.2 ms │

├──────────┼──────────┼───────────────┼────────┤

│ 10,000 │ 720 KB │ 11 ms │ 38 ms │

├──────────┼──────────┼───────────────┼────────┤

│ 50,000 │ 3.7 MB │ 68 ms │ 199 ms │

└──────────┴──────────┴───────────────┴────────┘

That works out to about 2.6µs per matched node, and it grows linearly with no blowup on bigger docs. The 2.6µs includes the plugin's own work (textContent + github-slugger), not just crossing the boundary.

So yes, the JS path costs more than Sätteri's own Rust work. On a doc packed with headings it's about 3x. In absolute terms it's still a few ms per thousand matches, and real docs have far fewer matches than this test.

Caveats: slug does very little work per node. katex/mathjax will cost more per math node, but rehype-katex pays that same rendering cost too. I haven't compared against unified + rehype-slug yet. That's next, and I'll add both benches to the repo.