Overview
The tab-icons plugin adds an icon to the labels of tab groups. A label gets the icon its text matches (npm, pnpm, vite.config.ts), or the one a [!keyword] marker at its start names. The icon is an inline <svg> before the label's text:
<input type="radio" name="..." id="..." hidden checked>
<label class="markdown-tabs-label" for="...">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" class="markdown-tab-icon" aria-hidden="true">...</svg>
npm
</label>
It's a port of vitepress-plugin-group-icons, which does the same for VitePress code groups, with its matching rules and its built-in icons. The icons come from VSCode Icons (MIT) and SVG Logos (CC0). In renderers without the plugin, a label's text matches nothing, and a marker stays a line of text.
Syntax
Matching a label
Write the tool or file the tab is about as its label. Package managers, runtimes, frameworks and build tools match by name:
npm install @mirrordown/remd-tabspnpm add @mirrordown/remd-tabsyarn add @mirrordown/remd-tabsbun add @mirrordown/remd-tabs% npm
> ```sh
> npm install @mirrordown/remd-tabs
> ```
% pnpm
> ```sh
> pnpm add @mirrordown/remd-tabs
> ```
% yarn
> ```sh
> yarn add @mirrordown/remd-tabs
> ```
% bun
> ```sh
> bun add @mirrordown/remd-tabs
> ```File names match by name, then by extension:
export default defineConfig({});{ "type": "module" }API_URL=http://localhost:3000fn main() {}% vite.config.ts
> ```ts
> export default defineConfig({});
> ```
% package.json
> ```json
> { "type": "module" }
> ```
% .env.local
> ```sh
> API_URL=http://localhost:3000
> ```
% main.rs
> ```rs
> fn main() {}
> ```Naming the icon
Start a label with [!keyword] to choose its icon, the way a GitHub alert names its type. The marker comes out of the label; the keyword is any built-in or configured icon's key, in any case, including extensions such as [!.ts]. A label that is only a marker reads as its keyword.
npm install @mirrordown/remd-tabsexport default { tabs: true };vite build% [!npm] Install
> ```sh
> npm install @mirrordown/remd-tabs
> ```
% [!.ts] Configure
> ```ts
> export default { tabs: true };
> ```
% [!vite]
> ```sh
> vite build
> ```[!none] turns matching off for one label. A keyword that names no icon isn't a marker: [!foo] Install stays as written. Nor is a marker that isn't plain text at the very start of the label: inside markup (**[!npm]** Install), or with a piece of it taken by markup ([!n**p**m]), it stays as written and the label is matched by its text. Markup after a marker is fine: [!npm] **Install**, and so is a keyword that is also a defined abbreviation: [!npm] is still the marker.
How a label is matched
Without a marker, the label's text is matched in this order, ignoring case:
- A keyword, as a whole word:
vitematchesVite 8andvite.config.ts, but notinvite. A keyword may run into ajs,rcorignoresuffix (eslintrc), and a camelCase label is split into words first, soVitePressmatchesvite. - A file name or extension the label ends with,
.tsinmain.ts; else one inside it,.envin.env.local.
When several keywords match, the longest wins, wherever it is in the label: npm or pnpm and pnpm or npm both get pnpm's icon. A keyword beats an extension, so deno.json gets Deno's icon and tsconfig.json gets TypeScript's config icon rather than JSON's. A label that matches nothing gets no icon and stays as it is.
Matching works on words, not meaning, so a label can match by accident: Next steps gets Next.js's icon. Write [!none] before such a label, or turn matching off with the match option and name every icon with a marker.
Two keywords: the longer one, pnpm, wins.
The longer keyword wins even when it comes second.
A camelCase label: Vite is a word of it.
A false match: next is a whole word.
Matching turned off for one label.
No match: vite isn't a whole word here.
No icon is named foo, so this isn't a marker.
% npm or pnpm
> Two keywords: the longer one, `pnpm`, wins.
% Vue + React
> The longer keyword wins even when it comes second.
% VitePress
> A camelCase label: `Vite` is a word of it.
% Next steps
> A false match: `next` is a whole word.
% [!none] Next steps
> Matching turned off for one label.
% Invitations
> No match: `vite` isn't a whole word here.
% [!foo] Install
> No icon is named `foo`, so this isn't a marker.Built-in icons
| Kind | Keys |
|---|---|
| Package managers and runtimes | npm pnpm yarn bun bunx deno |
| Frameworks | angular astro ember marko next nuxt qwik react solid svelte vue |
| Tools | esbuild eslint gradle oxc oxfmt oxlint prisma rolldown rollup tailwind tailwindcss unocss vite vitest vscode webpack |
| Files | editorconfig gitattributes gitignore tsconfig package.json uno.config.ts .env |
| Extensions | .c .cjs .cpp .cs .css .cts .dart .gjs .go .groovy .gts .html .ico .ini .java .js .json .jsp .jsx .kt .less .lua .md .mjs .mts .php .py .r .rb .rs .sass .scala .scss .sln .swift .toml .ts .tsx .wasm .yaml .yml |
Some built-in icons define a gradient or a clip path with an id of its own, namespaced markdown-tab-icon-…. An icon that appears more than once in a document is written out each time, so those ids repeat, each time on the same definition.
Configuration
All options are passed when registering the plugin.
Add or replace icons
icons maps keys to SVG markup. A key with a . is matched as a file name or extension, any other key as a keyword, and a key that is also built in, in any case, replaces that icon. Your file names and extensions are tried before the built-in ones, so .vitepress matches .vitepress/config.ts before .ts does; the longest keyword still wins, and of two of the same length yours does. Icons from Iconify work well: copy an icon's SVG. An icon is one <svg> element, which takes the icon's class and aria-hidden: markup that starts with anything else (an XML declaration, a comment, an <img>) throws when the plugin is created.
rehypeTabIcons({
icons: {
docker: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">...</svg>`,
},
})md.use(tabIcons, {
icons: {
docker: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">...</svg>`,
},
})satteriTabIcons({
icons: {
docker: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">...</svg>`,
},
})An icon drawn for one background can take a { light, dark } pair instead: both render, and the stylesheet shows the one for the color scheme.
icons: {
".vitepress": {
light: `<svg ...>...</svg>`,
dark: `<svg ...>...</svg>`,
},
}
Other options
| Option | Default | |
|---|---|---|
builtin |
true |
false leaves out the built-in icons, so only yours match. |
match |
true |
false turns matching off: only labels with a marker get an icon. |
containerClass |
"markdown-tabs" |
The tab groups' class, if you changed the tabs plugin's. |
Accessibility
The icon is aria-hidden: the label's text names the tab, and the icon only decorates it. The marker comes out of the label and out of its panel's aria-label, so a screen reader reads Install, not [!npm] Install.
Customization
The stylesheet keeps its rules in @layer markdown-tab-icons, so any unlayered CSS you write overrides them. An icon fills a square as tall as the label's capital letters (1cap), with its drawing fitted inside, so it scales with the label's font.
.markdown-tab-icon {
inline-size: 1.2cap;
block-size: 1.2cap;
}
Icons with light and dark variants follow the reader's preferred color scheme. A site with its own theme switch can show them by it instead, with unlayered rules:
:root[data-theme="light"] .markdown-tab-icon[data-scheme="light"],
:root[data-theme="dark"] .markdown-tab-icon[data-scheme="dark"] {
display: revert;
}
:root[data-theme="light"] .markdown-tab-icon[data-scheme="dark"],
:root[data-theme="dark"] .markdown-tab-icon[data-scheme="light"] {
display: none;
}
Usage
The plugin decorates the tab groups that the tabs plugin builds, so install that too. Register it once: a second copy reads the labels the first one changed, so it adds a second icon and matches a label whose [!none] has already come out (unified ignores a plugin registered twice; markdown-it and Sätteri run both).
The remark package ships rehypeTabIcons, a rehype plugin: register it after remark-rehype, with the tabs plugin's handlers. It adds each <svg> as a raw node, so it reaches the HTML exactly as the other engines write it; stringify with allowDangerousHtml: true (Astro already does).
npm install @mirrordown/remd-tab-iconsimport { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import { remarkTabs, tabsHastHandlers } from "@mirrordown/remd-tabs";
import { rehypeTabIcons } from "@mirrordown/remd-tab-icons";
import "@mirrordown/remd-tabs/tabs.css";
import "@mirrordown/remd-tab-icons/tab-icons.css";
const processor = unified()
.use(remarkParse)
.use(remarkTabs)
.use(remarkRehype, { handlers: tabsHastHandlers })
.use(rehypeTabIcons)
.use(rehypeStringify, { allowDangerousHtml: true });// astro.config.ts
import { defineConfig } from "astro/config";
import { remarkTabs, tabsHastHandlers } from "@mirrordown/remd-tabs";
import { rehypeTabIcons } from "@mirrordown/remd-tab-icons";
export default defineConfig({
markdown: {
remarkPlugins: [remarkTabs],
remarkRehype: { handlers: tabsHastHandlers },
rehypePlugins: [rehypeTabIcons],
},
});
// In your layout:
import "@mirrordown/remd-tabs/tabs.css";
import "@mirrordown/remd-tab-icons/tab-icons.css";npm install @mirrordown/mdit-tab-iconsInstall it after the tabs plugin. Before it, the icons are the same, but a marker is read from the label's source instead of its text, and a group whose marker came out gets other ids than the other engines give it.
import MarkdownIt from "markdown-it";
import { tabs } from "@mirrordown/mdit-tabs";
import { tabIcons } from "@mirrordown/mdit-tab-icons";
import "@mirrordown/mdit-tabs/styles";
import "@mirrordown/mdit-tab-icons/styles";
const md = new MarkdownIt().use(tabs).use(tabIcons);// .vitepress/config.ts
import { defineConfig } from "vitepress";
import { tabs } from "@mirrordown/mdit-tabs";
import { tabIcons } from "@mirrordown/mdit-tab-icons";
import "@mirrordown/mdit-tabs/styles";
import "@mirrordown/mdit-tab-icons/styles";
export default defineConfig({
markdown: {
config: (md) => md.use(tabs).use(tabIcons),
},
});npm install @mirrordown/sat-tab-iconsimport { markdownToHtml } from "satteri";
import { satteriTabs } from "@mirrordown/sat-tabs";
import { satteriTabIcons } from "@mirrordown/sat-tab-icons";
import "@mirrordown/sat-tabs/tabs.css";
import "@mirrordown/sat-tab-icons/tab-icons.css";
const { html } = markdownToHtml(source, {
mdastPlugins: [satteriTabs()],
hastPlugins: [satteriTabIcons()],
});// astro.config.ts
import { defineConfig } from "astro/config";
import { satteri } from "@astrojs/markdown-satteri";
import { satteriTabs } from "@mirrordown/sat-tabs";
import { satteriTabIcons } from "@mirrordown/sat-tab-icons";
export default defineConfig({
markdown: {
processor: satteri({
mdastPlugins: [satteriTabs()],
hastPlugins: [satteriTabIcons()],
}),
},
});
// In your layout:
import "@mirrordown/sat-tabs/tabs.css";
import "@mirrordown/sat-tab-icons/tab-icons.css";