· 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.tsis a rehype plugin, first inrehypePluginsinvite.config.ts(beforerehype-slug). 15 tests incallouts.test.ts, run through mdsvex's owncompile().- The title is always text: the type ("Tip"), or the custom title with the type before it as
.visually-hiddentext ("Warning: Not on GitHub Pages"). The Lucide icon is an inline<svg aria-hidden="true">built at build time from the plainlucidepackage (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-everywhereuses 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;fileis the file being compiled. mdsvex keeps its name infile.filename, not in the usualfile.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()returnedundefined: mdsvex only handles itsextensions(.svxby default), so the test passesextensions: ['.md']like the Vite plugin does. - My own icon type didn't fit Lucide's (
SVGPropsallows numbers);lucideexportsIconNode, so I used that.
Links
Next
- Phase 9.5 step 2: fenced-block components (
videofirst).