· 3 min read

Callouts in markdown

Callouts: a blockquote that starts with [!type] becomes an <aside class="callout"> with an icon and a title. It's the syntax GitHub ("alerts") and Obsidian…

What we did

  • Callouts: a blockquote that starts with [!type] becomes an <aside class="callout"> with an icon and a title. It's the syntax GitHub ("alerts") and Obsidian ("callouts") already draw, so the same file reads well in the vault, on GitHub and here. Anywhere else it's a plain blockquote.
  • GitHub's five types: note, tip, important, warning, caution (any case). Obsidian's custom title (> [!warning] Not on GitHub Pages) works, inline code and bold included. Obsidian's folding sign ([!note]-) is accepted but the box is shown open: folding is left for later.
  • An unknown type ([!info]) fails the build, naming the file and listing the five.
  • src/lib/callouts.ts is a rehype plugin, first in rehypePlugins in vite.config.ts (before rehype-slug). 15 tests in callouts.test.ts, run through mdsvex's own compile().
  • The title is always text: the type ("Tip"), or the custom title with the type before it as .visually-hidden text ("Warning: Not on GitHub Pages"). The Lucide icon is an inline <svg aria-hidden="true"> built at build time from the plain lucide package (no JS).
  • Five tokens --callout-note … --callout-caution (GitHub's colours from our syntax steps), added to the contrast checker. On --surface-2, the box's background: light ≥ 5.40:1, dark ≥ 7.45:1.
  • The draft callouts-that-read-well-everywhere uses all of it; the publishing guide (content/blog/published/README.md) has a Callouts section.
  • Checked: Lighthouse accessibility 100 on the draft in both themes (dev), no horizontal scroll at 320px.

What I learned

  • mdsvex builds a post in steps: markdown → markdown tree (mdast) → HTML tree (hast) → Svelte code. Remark plugins change the first tree, rehype plugins the second.
  • mdsvex 0.12 bundles an old parser (remark-parse 8), so modern remark plugins for callouts don't run on it. The HTML tree hasn't changed shape, so a rehype plugin works in any version.
  • A rehype plugin is a function that returns (tree, file) => …. It changes the tree in place; file is the file being compiled. mdsvex keeps its name in file.filename, not in the usual file.path.
  • A flex container makes every child node an item, text nodes included: a title like "Use pnpm" would be three items with gaps between them. So the title's text sits in one <span>.

Problems & fixes

  • The old parser reads [!tip] as a link to a reference called !tip. It finds none and puts the text back, but as a separate text node. The plugin joins the text nodes at the start of the paragraph before matching.
  • In the tests, compile() returned undefined: mdsvex only handles its extensions (.svx by default), so the test passes extensions: ['.md'] like the Vite plugin does.
  • My own icon type didn't fit Lucide's (SVGProps allows numbers); lucide exports IconNode, so I used that.

Next

  • Phase 9.5 step 2: fenced-block components (video first).