On straffesites.com, every fenced code block in a blog post renders as a small terminal window: a title bar with three dots, a language label, and the Shiki-highlighted code underneath. The posts are MDX files in an Astro project. Nobody converts code blocks by hand. One build-time plugin does it for every post in both languages.

The obvious tool for that job used to be a rehype plugin. Astro 7 renders .md and .mdx with Sätteri by default, a Markdown processor written in Rust that has its own plugin format. This post shows the working plugin, how to test it, and three traps. I reproduced each one in a small demo build instead of taking it from the docs.

Versions used for every output below: Astro 7.2.8, @astrojs/markdown-satteri 0.3.8, @astrojs/mdx 7.0.8, satteri 0.10.5, Node 26.

The target HTML

Shiki already turns a fence into <pre class="astro-code ..." data-language="js">. The plugin only needs to wrap that pre:

<div class="terminal-window code-terminal"> <div class="terminal-bar"> <div class="terminal-dots" aria-hidden="true"><span></span><span></span><span></span></div> <span class="terminal-lang">js</span> </div> <div class="terminal-screen"> <pre class="astro-code github-dark" data-language="js">...</pre> </div> </div> 

The styling is plain CSS on those class names, so I'm leaving it out here. Fences labeled text or plaintext get the dots but no label.

Trap 1: markdown.rehypePlugins doesn't run on Sätteri

A Sätteri processor doesn't run unified/rehype plugins. What happens to your old rehypePlugins depends on whether you also set a processor. I tested both with a small rehype plugin that wraps every pre in <div class="rehype-wrapped">.

With markdown.processor: satteri() and markdown.rehypePlugins both set, the build succeeds, the plugin never runs, and you only get this line in the build log:

[astro] `markdown.remarkPlugins`/`rehypePlugins`/`remarkRehype` are set, but your `satteri` processor doesn't run them. Move them to `unified({...})` from `@astrojs/markdown-remark` and set `markdown.processor: unified({...})` if you want them to apply. 

Without an explicit processor, Astro quietly switches the whole project back to the unified pipeline and the rehype plugin does run:

[astro] `markdown.remarkPlugins`, `markdown.rehypePlugins`, and `markdown.remarkRehype` are deprecated. Pass them to `unified({...})` from `@astrojs/markdown-remark` directly instead. 

That second case needs @astrojs/markdown-remark installed. Astro's config validation throws an install hint if it isn't. So "my rehype plugin works" can mean you're no longer on Sätteri at all. If you want to stay on Sätteri, write a Sätteri hast plugin and pass it through satteri({ hastPlugins }).

The plugin

A Sätteri hast plugin is an object with a name and a visitor. element.filter limits the visitor to certain tag names. If visit returns a node, that node replaces the visited one.

// plugins/code-terminal.js const classList = (node) => { const { class: cls, className } = node.properties ?? {}; return [ ...(typeof cls === 'string' ? cls.split(/\s+/) : []), ...(Array.isArray(className) ? className : []), ].filter(Boolean); }; const isHighlightedPre = (node) => { if (node.tagName !== 'pre') return false; const classes = classList(node); return ( classes.includes('astro-code') || classes.includes('shiki') || typeof node.properties?.dataLanguage === 'string' ); }; const languageLabel = (node) => { const lang = String(node.properties?.dataLanguage ?? '').trim().toLowerCase(); return lang && lang !== 'plaintext' && lang !== 'text' ? lang : ''; }; const el = (tagName, properties, children = []) => ({ type: 'element', tagName, properties, children, }); export function codeTerminalPlugin() { return { name: 'code-terminal', element: { filter: ['pre'], visit(node) { if (!isHighlightedPre(node)) return; const dots = el('div', { className: ['terminal-dots'], ariaHidden: 'true' }, [ el('span', {}), el('span', {}), el('span', {}), ]); const label = languageLabel(node); const bar = el( 'div', { className: ['terminal-bar'] }, label ? [dots, el('span', { className: ['terminal-lang'] }, [{ type: 'text', value: label }])] : [dots], ); const screen = el('div', { className: ['terminal-screen'] }, [node]); // Return the replacement instead of calling ctx.wrapNode(). return el('div', { className: ['terminal-window', 'code-terminal'] }, [bar, screen]); }, }, }; } 

This is a condensed version of the plugin that runs on straffesites.com. The original has the same logic with longer comments. Register it in the processor:

// astro.config.mjs import { defineConfig } from 'astro/config'; import mdx from '@astrojs/mdx'; import { satteri } from '@astrojs/markdown-satteri'; import { codeTerminalPlugin } from './plugins/code-terminal.js'; export default defineConfig({ integrations: [mdx()], markdown: { processor: satteri({ hastPlugins: [codeTerminalPlugin] }), }, }); 

The MDX integration picks up the same processor and its hastPlugins, so one registration covers .md and .mdx. The Astro docs tell you to install @astrojs/markdown-satteri before you import it, so do that.

Why pre is already highlighted

You might expect to see raw <pre><code> here. In the Astro integration, the order is fixed in @astrojs/markdown-satteri: Astro's own highlight plugin runs first, then your hastPlugins, then image handling and heading IDs. The MDX path uses the same order. Shiki has already replaced the node by the time your visitor runs.

I logged what a visitor actually receives with a probe plugin:

[probe] pre class= "astro-code github-dark" dataLanguage= js 

Shiki outputs class="shiki", but Astro's highlighter renames it to astro-code before returning the tree, so your visitor sees astro-code already. The shiki and className checks are only a fallback. data-language is the marker to rely on.

Trap 2: wrapNode() plus insertBefore() puts the bar outside the window

The visitor context has methods that look made for this: ctx.wrapNode(node, parent) and ctx.insertBefore(node, newNode). The obvious version wraps the pre and then inserts the title bar before it:

visit(node, ctx) { if (typeof node.properties?.dataLanguage !== 'string') return; ctx.wrapNode(node, { type: 'element', tagName: 'div', properties: { className: ['terminal-window'] }, children: [] }); ctx.insertBefore(node, { type: 'element', tagName: 'div', properties: { className: ['terminal-bar'] }, children: [] }); }, 

The build passes. The HTML doesn't match what you meant (Shiki spans left out):

<div class="terminal-bar"></div><div class="terminal-window"><pre class="astro-code github-dark" ...>...</pre></div> 

The bar is a sibling of the wrapper, not its first child. In this build, insertBefore placed the new node next to the wrapper in the parent, not next to the pre inside it. Building the full subtree and returning it from visit avoids the whole question. It's one replacement, and the wrapper contains exactly what you put in it.

Trap 3: a boolean aria-hidden serializes differently in .md and .mdx

The dots are decoration, so they get aria-hidden. In hast, a boolean true feels natural: ariaHidden: true. Render the same plugin through both pipelines and you get:

<!-- .mdx page --> <div class="terminal-dots" aria-hidden="true"> <!-- .md page --> <div class="terminal-dots" aria-hidden> 

A bare aria-hidden has an empty value. aria-hidden isn't an HTML boolean attribute. It's an ARIA state with the values true, false, and undefined, and an empty string doesn't count as true. On .md pages, screen readers would still see the decoration.

The production site only uses MDX, so it was rendering aria-hidden="true" and this never showed up live. I found it while building the demo for this post and fixed it with the string 'true', which renders the same in both pipelines.

Testing the plugin without a full build

createSatteriMarkdownProcessor renders Markdown with the same plugin order Astro uses, outside of a build. That makes the .md path a fast node:test:

import test from 'node:test'; import assert from 'node:assert/strict'; import { createSatteriMarkdownProcessor } from '@astrojs/markdown-satteri'; import { codeTerminalPlugin } from '../src/utils/code-terminal-plugin.js'; const render = async (markdown) => { const processor = await createSatteriMarkdownProcessor({ syntaxHighlight: 'shiki', hastPlugins: [codeTerminalPlugin], }); return (await processor.render(markdown)).code; }; test('code-terminal hides the decorative dots with an explicit aria-hidden="true" in .md output', async () => { const html = await render('``` text\nplain output\n ```\n'); assert.ok(html.includes('<div class="terminal-dots" aria-hidden="true">'), html.slice(0, 200)); assert.ok(!html.includes('terminal-lang'), 'text fences get no language label'); }); 

Shiki is already the default for syntaxHighlight. I set it explicitly anyway. If highlighting were ever off, the pre would have no data-language, the plugin would correctly do nothing, and a test that only checks for missing output could pass for the wrong reason. Against the old boolean version, this test fails and prints aria-hidden><span>. With the string, it passes. On the site, the test runs before the build, and a separate output check after the build counts the wrapped pre elements in a real post.

Takeaways

  • On Astro 7, check which processor actually runs. A rehype plugin that "works" may have quietly moved you back to unified.
  • In a Sätteri hast visitor, return the new subtree from visit instead of chaining wrapNode and insertBefore.
  • Match on data-language, not on Shiki class names.
  • Write ARIA values as strings in hast, and test the .md path even if you only write MDX today.

You can see the result on any post with code on straffesites.com.