@mirrordown/remd-tab-icons 0.0.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,64 @@
1
+ # Changelog
2
+
3
+
4
+ ## 0.1.1
5
+ <sub>2026-11-17</sub>
6
+
7
+ - *(patch)*
8
+ Fixes for labels whose `[!keyword]` marker sits next to other markup, and for the `icons` and `containerClass` options.
9
+
10
+ - **A marker followed by inline markup no longer repeats the label** (all engines).
11
+
12
+ ```markdown
13
+ % [!npm] **Install**
14
+ > Body.
15
+ ```
16
+
17
+ Was the label `<svg…/>Install<strong>Install</strong>`. Now `<svg…/><strong>Install</strong>`. The same happened with a code span: ``% [!npm] `npm i` `` rendered `npm i<code>npm i</code>`.
18
+
19
+ - **A marker is read only at the start of the label's text** (all engines).
20
+
21
+ ```markdown
22
+ % **[!npm]** Install
23
+ > Body.
24
+ ```
25
+
26
+ Was the label as written but the panel's `aria-label` cut down to `Install` (and in markdown-it an extra `Install` before the `<strong>`). Now the label as written with `aria-label="[!npm] Install"`; the label still gets the npm icon, matched by its text. The same goes for a marker in a code span, and for one split by emphasis (`[!n**p**m]`), which rendered `Install<strong>p</strong>m] Install`.
27
+
28
+ - **A marker whose keyword is a defined abbreviation is still a marker** (all engines), with the abbr plugin.
29
+
30
+ ```markdown
31
+ *[npm]: Node Package Manager
32
+
33
+ % [!npm] Install
34
+ > Body.
35
+ ```
36
+
37
+ Was the label `<svg…/>Install<abbr title="Node Package Manager">npm</abbr>] Install`. Now `<svg…/>Install`.
38
+
39
+ - **The markdown-it plugin honours `containerClass`.** It added icons to every tab group whatever the option said, where remark and Sätteri only touch groups that carry the class. If you give the tabs plugin a `containerClass`, pass the same value to tab-icons, in every engine: without it markdown-it now leaves those labels alone, as the other two always did.
40
+
41
+ - **An icon of yours wins a tie with a built-in keyword of the same length** (all engines), here with `icons: { cargo: … }`.
42
+
43
+ ```markdown
44
+ % cargo and react
45
+ > Body.
46
+ ```
47
+
48
+ Was the built-in React icon. Now your `cargo` icon. A longer keyword still wins over a shorter one.
49
+
50
+ - **A key in `icons` replaces a built-in icon whatever its case** (all engines). With `icons: { NPM: … }`, a `[!npm]` marker got your icon while a label reading `npm` kept the built-in one; both now get yours.
51
+
52
+ - **Your SVG markup keeps its attributes** (all engines). An icon written with single-quoted attributes (`<svg viewBox='0 0 24 24'>`) or unquoted ones (`<svg width=24 height=24>`) lost them, and with them its size; they are now kept, written back in double quotes. A `>` inside an attribute value no longer cuts the tag short.
53
+
54
+ - **A self-closing `<svg … />` icon is closed** (all engines). It was written without its end, so the label's text became the icon's content; it is now `<svg …></svg>` followed by the label.
55
+
56
+ - **An icon whose markup does not start with `<svg` is refused when the plugin is created** (all engines). `icons: { cargo: '<img src="cargo.png" alt="">' }` used to be emitted as it was, without the icon's class or `aria-hidden`; it now throws a `TypeError` naming the key. A `{ light, dark }` pair missing one variant throws at the same point instead of at render.
57
+
58
+ - **The ids inside the built-in icons are named after the icon** (all engines). Icons that carry gradients or clip paths had short random ids such as `SVGgudELdDz`; they are now `markdown-tab-icon-<collection>-<name>-<n>`, so they cannot collide with another inline SVG on the page. An icon used twice in a document still repeats its ids, which the guide now says.
59
+
60
+ ## 0.1.0
61
+ <sub>2026-10-28</sub>
62
+
63
+ - *(minor)*
64
+ Add the tab-icons plugin set, a port of vitepress-plugin-group-icons for Mirrordown's tabs: each tab label gets the icon its text matches (a keyword such as `npm`, `pnpm` or `vite` as a whole word, the longest winning, else a file name or extension such as `package.json` or `.ts`), or the one a `[!keyword]` marker at its start names; `[!none]` turns matching off for one label. The icon is an inline `<svg class="markdown-tab-icon" aria-hidden="true">` before the label's text, and the marker comes out of the label and its panel's `aria-label`. It ships group-icons' built-in icons (from VSCode Icons and SVG Logos); the `icons` option adds or replaces them, with light and dark pairs, and `builtin` and `match` turn the built-in icons and matching off. The markdown-it, remark and Sätteri plugins emit identical HTML.
package/README.md CHANGED
@@ -1,9 +1,249 @@
1
1
  # @mirrordown/remd-tab-icons
2
2
 
3
- 🐣 This package name has been claimed with [fledgling](https://github.com/dmno-dev/fledgling) for [https://github.com/mirrordown/mirrordown](https://github.com/mirrordown/mirrordown), and a real release will land here soon.
3
+ > Part of [Mirrordown](https://github.com/mirrordown/mirrordown) — a suite of markdown syntax extensions for the unified, markdown-it and Sätteri ecosystems.
4
4
 
5
- This is a placeholder — there is nothing to install yet.
5
+ A remark/rehype (unified) plugin for the `tab-icons` syntax extension.
6
6
 
7
- ---
7
+ ## Overview
8
8
 
9
- Want to claim a name of your own? Run `npx fledgling add <name> --new --yes` — it reserves the name on npm and can set up token-less (OIDC trusted) publishing for when you are ready.
9
+ The `tab-icons` plugin adds an icon to the labels of [tab groups](/guide/plugins/tabs). 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:
10
+
11
+ ```html
12
+ <input type="radio" name="..." id="..." hidden checked>
13
+ <label class="markdown-tabs-label" for="...">
14
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" class="markdown-tab-icon" aria-hidden="true">...</svg>
15
+ npm
16
+ </label>
17
+ ```
18
+
19
+ It's a port of [vitepress-plugin-group-icons](https://github.com/yuyinws/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](https://github.com/vscode-icons/vscode-icons) (MIT) and [SVG Logos](https://github.com/gilbarbara/logos) (CC0). In renderers without the plugin, a label's text matches nothing, and a marker stays a line of text.
20
+
21
+ ## Syntax
22
+
23
+ ### Matching a label
24
+
25
+ Write the tool or file the tab is about as its label. Package managers, runtimes, frameworks and build tools match by name:
26
+
27
+ ````markdown
28
+ % npm
29
+ > ```sh
30
+ > npm install @mirrordown/remd-tabs
31
+ > ```
32
+ % pnpm
33
+ > ```sh
34
+ > pnpm add @mirrordown/remd-tabs
35
+ > ```
36
+ % yarn
37
+ > ```sh
38
+ > yarn add @mirrordown/remd-tabs
39
+ > ```
40
+ % bun
41
+ > ```sh
42
+ > bun add @mirrordown/remd-tabs
43
+ > ```
44
+ ````
45
+
46
+ File names match by name, then by extension:
47
+
48
+ ````markdown
49
+ % vite.config.ts
50
+ > ```ts
51
+ > export default defineConfig({});
52
+ > ```
53
+ % package.json
54
+ > ```json
55
+ > { "type": "module" }
56
+ > ```
57
+ % .env.local
58
+ > ```sh
59
+ > API_URL=http://localhost:3000
60
+ > ```
61
+ % main.rs
62
+ > ```rs
63
+ > fn main() {}
64
+ > ```
65
+ ````
66
+
67
+ ### Naming the icon
68
+
69
+ Start a label with `[!keyword]` to choose its icon, the way a [GitHub alert](/guide/plugins/github-alerts) 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.
70
+
71
+ ````markdown
72
+ % [!npm] Install
73
+ > ```sh
74
+ > npm install @mirrordown/remd-tabs
75
+ > ```
76
+ % [!.ts] Configure
77
+ > ```ts
78
+ > export default { tabs: true };
79
+ > ```
80
+ % [!vite]
81
+ > ```sh
82
+ > vite build
83
+ > ```
84
+ ````
85
+
86
+ `[!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](/guide/plugins/abbr): `[!npm]` is still the marker.
87
+
88
+ ## How a label is matched
89
+
90
+ Without a marker, the label's text is matched in this order, ignoring case:
91
+
92
+ 1. **A keyword**, as a whole word: `vite` matches `Vite 8` and `vite.config.ts`, but not `invite`. A keyword may run into a `js`, `rc` or `ignore` suffix (`eslintrc`), and a camelCase label is split into words first, so `VitePress` matches `vite`.
93
+ 2. **A file name or extension** the label ends with, `.ts` in `main.ts`; else one inside it, `.env` in `.env.local`.
94
+
95
+ 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.
96
+
97
+ 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.
98
+
99
+ ````markdown
100
+ % npm or pnpm
101
+ > Two keywords: the longer one, `pnpm`, wins.
102
+ % Vue + React
103
+ > The longer keyword wins even when it comes second.
104
+ % VitePress
105
+ > A camelCase label: `Vite` is a word of it.
106
+ % Next steps
107
+ > A false match: `next` is a whole word.
108
+ % [!none] Next steps
109
+ > Matching turned off for one label.
110
+ % Invitations
111
+ > No match: `vite` isn't a whole word here.
112
+ % [!foo] Install
113
+ > No icon is named `foo`, so this isn't a marker.
114
+ ````
115
+
116
+ ### Built-in icons
117
+
118
+ | Kind | Keys |
119
+ | --- | --- |
120
+ | Package managers and runtimes | `npm` `pnpm` `yarn` `bun` `bunx` `deno` |
121
+ | Frameworks | `angular` `astro` `ember` `marko` `next` `nuxt` `qwik` `react` `solid` `svelte` `vue` |
122
+ | Tools | `esbuild` `eslint` `gradle` `oxc` `oxfmt` `oxlint` `prisma` `rolldown` `rollup` `tailwind` `tailwindcss` `unocss` `vite` `vitest` `vscode` `webpack` |
123
+ | Files | `editorconfig` `gitattributes` `gitignore` `tsconfig` `package.json` `uno.config.ts` `.env` |
124
+ | 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` |
125
+
126
+ 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.
127
+
128
+ ## Configuration
129
+
130
+ All options are passed when registering the plugin.
131
+
132
+ ### Add or replace icons
133
+
134
+ `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](https://icon-sets.iconify.design/) 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.
135
+
136
+ ```ts
137
+ rehypeTabIcons({
138
+ icons: {
139
+ docker: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">...</svg>`,
140
+ },
141
+ })
142
+ ```
143
+
144
+ 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.
145
+
146
+ ```ts
147
+ icons: {
148
+ ".vitepress": {
149
+ light: `<svg ...>...</svg>`,
150
+ dark: `<svg ...>...</svg>`,
151
+ },
152
+ }
153
+ ```
154
+
155
+ ### Other options
156
+
157
+ | Option | Default | |
158
+ | --- | --- | --- |
159
+ | `builtin` | `true` | `false` leaves out the built-in icons, so only yours match. |
160
+ | `match` | `true` | `false` turns matching off: only labels with a marker get an icon. |
161
+ | `containerClass` | `"markdown-tabs"` | The tab groups' class, if you changed the tabs plugin's. |
162
+
163
+ ## Accessibility
164
+
165
+ 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`.
166
+
167
+ ## Customization
168
+
169
+ 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.
170
+
171
+ ```css
172
+ .markdown-tab-icon {
173
+ inline-size: 1.2cap;
174
+ block-size: 1.2cap;
175
+ }
176
+ ```
177
+
178
+ 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:
179
+
180
+ ```css
181
+ :root[data-theme="light"] .markdown-tab-icon[data-scheme="light"],
182
+ :root[data-theme="dark"] .markdown-tab-icon[data-scheme="dark"] {
183
+ display: revert;
184
+ }
185
+
186
+ :root[data-theme="light"] .markdown-tab-icon[data-scheme="dark"],
187
+ :root[data-theme="dark"] .markdown-tab-icon[data-scheme="light"] {
188
+ display: none;
189
+ }
190
+ ```
191
+
192
+ The plugin decorates the tab groups that the [tabs](/guide/plugins/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).
193
+
194
+ ## Install
195
+
196
+ 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).
197
+
198
+ ```sh
199
+ npm install @mirrordown/remd-tab-icons
200
+ ```
201
+
202
+ ### Unified
203
+
204
+ ```ts
205
+ import { unified } from "unified";
206
+ import remarkParse from "remark-parse";
207
+ import remarkRehype from "remark-rehype";
208
+ import rehypeStringify from "rehype-stringify";
209
+ import { remarkTabs, tabsHastHandlers } from "@mirrordown/remd-tabs";
210
+ import { rehypeTabIcons } from "@mirrordown/remd-tab-icons";
211
+ import "@mirrordown/remd-tabs/tabs.css";
212
+ import "@mirrordown/remd-tab-icons/tab-icons.css";
213
+
214
+ const processor = unified()
215
+ .use(remarkParse)
216
+ .use(remarkTabs)
217
+ .use(remarkRehype, { handlers: tabsHastHandlers })
218
+ .use(rehypeTabIcons)
219
+ .use(rehypeStringify, { allowDangerousHtml: true });
220
+ ```
221
+
222
+ ### Astro
223
+
224
+ ```ts
225
+ // astro.config.ts
226
+ import { defineConfig } from "astro/config";
227
+ import { remarkTabs, tabsHastHandlers } from "@mirrordown/remd-tabs";
228
+ import { rehypeTabIcons } from "@mirrordown/remd-tab-icons";
229
+
230
+ export default defineConfig({
231
+ markdown: {
232
+ remarkPlugins: [remarkTabs],
233
+ remarkRehype: { handlers: tabsHastHandlers },
234
+ rehypePlugins: [rehypeTabIcons],
235
+ },
236
+ });
237
+
238
+ // In your layout:
239
+ import "@mirrordown/remd-tabs/tabs.css";
240
+ import "@mirrordown/remd-tab-icons/tab-icons.css";
241
+ ```
242
+
243
+ ## Documentation
244
+
245
+ Full documentation, more examples, and configuration options: [github.com/mirrordown/mirrordown](https://github.com/mirrordown/mirrordown) (dedicated docs site coming soon).
246
+
247
+ ## License
248
+
249
+ MIT © [Drake Costa](https://saeris.gg)
@@ -0,0 +1,9 @@
1
+ import { TabIcon, TabIconsOptions, TabIconsOptions as TabIconsOptions$1 } from "@mirrordown/core/tab-icons";
2
+ import { Root } from "hast";
3
+ import { Plugin } from "unified";
4
+ /**
5
+ * rehype plugin that adds an icon to each tab label of `@mirrordown/remd-tabs`: the one a `[!keyword]` marker at the start of the label names (`% [!npm] Install`), or, without a marker, the one the label's text matches (`% npm`, `% vite.config.ts`), as vitepress-plugin-group-icons matches code-group labels. The icon is an inline `<svg class="markdown-tab-icon" aria-hidden="true">` before the label's text, as a `raw` node, so it reaches the HTML exactly as the markdown-it and Sätteri plugins write it (stringify with `allowDangerousHtml`); the marker comes out of the label and the panel's `aria-label`. The matching and the icons are shared through `@mirrordown/core`.
6
+ */
7
+ export declare const rehypeTabIcons: Plugin<[TabIconsOptions$1?], Root>;
8
+ export type { TabIcon, TabIconsOptions };
9
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":["TabIconsOptions"],"sources":["../src/index.ts"],"mappings":";;;;;;qBA+Ba,gBAAgB,QAAQA,qBAAmB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,56 @@
1
+ import { visit } from "unist-util-visit";
2
+ import { createTabIconResolver, tabIconMarkup } from "@mirrordown/core/tab-icons";
3
+ // src/index.ts
4
+ const hasClass = (node, name) => {
5
+ if (node?.type !== `element`) return false;
6
+ const value = node.properties.className ?? node.properties.class;
7
+ return Array.isArray(value) ? value.includes(name) : typeof value === `string` && value.split(` `).includes(name);
8
+ };
9
+ const childrenWithClass = (parent, name) => (parent?.children ?? []).filter((child) => hasClass(child, name));
10
+ /**
11
+ * rehype plugin that adds an icon to each tab label of `@mirrordown/remd-tabs`: the one a `[!keyword]` marker at the start of the label names (`% [!npm] Install`), or, without a marker, the one the label's text matches (`% npm`, `% vite.config.ts`), as vitepress-plugin-group-icons matches code-group labels. The icon is an inline `<svg class="markdown-tab-icon" aria-hidden="true">` before the label's text, as a `raw` node, so it reaches the HTML exactly as the markdown-it and Sätteri plugins write it (stringify with `allowDangerousHtml`); the marker comes out of the label and the panel's `aria-label`. The matching and the icons are shared through `@mirrordown/core`.
12
+ */
13
+ const rehypeTabIcons = (options = {}) => {
14
+ const resolve = createTabIconResolver(options);
15
+ const { containerClass = `markdown-tabs` } = options;
16
+ return (tree) => {
17
+ visit(tree, `element`, (node) => {
18
+ if (!hasClass(node, containerClass)) return;
19
+ const [labelsRow] = childrenWithClass(node, `${containerClass}-labels`);
20
+ const [panelsRow] = childrenWithClass(node, `${containerClass}-panels`);
21
+ const labels = childrenWithClass(labelsRow, `${containerClass}-label`);
22
+ const panels = childrenWithClass(panelsRow, `${containerClass}-panel`);
23
+ for (const [index, label] of labels.entries()) {
24
+ const panel = panels[index];
25
+ const key = panel && `aria-label` in panel.properties ? `aria-label` : `ariaLabel`;
26
+ const plain = panel?.properties[key];
27
+ const first = label.children[0]?.type === `text` ? label.children[0] : void 0;
28
+ const [, abbr, after] = label.children;
29
+ const term = abbr?.type === `element` && abbr.tagName === `abbr` && abbr.children.length === 1 && abbr.children[0]?.type === `text` ? abbr.children[0] : void 0;
30
+ const split = first?.value === `[!` && abbr && term && after?.type === `text` && after.value.startsWith(`]`) ? {
31
+ abbr,
32
+ after,
33
+ lead: first.value + term.value + after.value
34
+ } : void 0;
35
+ const { icon, marker, label: text } = resolve(typeof plain === `string` ? plain : ``, split?.lead ?? first?.value ?? ``);
36
+ if (marker && split) {
37
+ split.after.value = split.lead.slice(marker.length);
38
+ const only = label.children.length === 3 && split.after.value === ``;
39
+ label.children.splice(0, 3, ...only ? [split.abbr] : [], ...split.after.value ? [split.after] : []);
40
+ if (panel) panel.properties[key] = text;
41
+ } else if (marker && first) {
42
+ first.value = first.value.slice(marker.length) || (label.children.length === 1 ? text : ``);
43
+ if (first.value === ``) label.children.shift();
44
+ if (panel) panel.properties[key] = text;
45
+ }
46
+ if (icon) label.children.unshift({
47
+ type: `raw`,
48
+ value: tabIconMarkup(icon)
49
+ });
50
+ }
51
+ });
52
+ };
53
+ };
54
+ export { rehypeTabIcons };
55
+
56
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Element, ElementContent, Root } from \"hast\";\nimport type { Plugin } from \"unified\";\nimport { visit } from \"unist-util-visit\";\nimport {\n createTabIconResolver,\n tabIconMarkup,\n type TabIconsOptions\n} from \"@mirrordown/core/tab-icons\";\n\nexport type { TabIcon, TabIconsOptions } from \"@mirrordown/core/tab-icons\";\n\nconst hasClass = (node: ElementContent | undefined, name: string): boolean => {\n if (node?.type !== `element`) return false;\n const value = node.properties.className ?? node.properties.class;\n return Array.isArray(value)\n ? value.includes(name)\n : typeof value === `string` && value.split(` `).includes(name);\n};\n\n// A group's own children with a class: its labels or panels (a group nested in a panel has its own).\nconst childrenWithClass = (\n parent: Element | undefined,\n name: string\n): Element[] =>\n (parent?.children ?? []).filter((child): child is Element =>\n hasClass(child, name)\n );\n\n/**\n * rehype plugin that adds an icon to each tab label of `@mirrordown/remd-tabs`: the one a `[!keyword]` marker at the start of the label names (`% [!npm] Install`), or, without a marker, the one the label's text matches (`% npm`, `% vite.config.ts`), as vitepress-plugin-group-icons matches code-group labels. The icon is an inline `<svg class=\"markdown-tab-icon\" aria-hidden=\"true\">` before the label's text, as a `raw` node, so it reaches the HTML exactly as the markdown-it and Sätteri plugins write it (stringify with `allowDangerousHtml`); the marker comes out of the label and the panel's `aria-label`. The matching and the icons are shared through `@mirrordown/core`.\n */\nexport const rehypeTabIcons: Plugin<[TabIconsOptions?], Root> = (\n options = {}\n) => {\n const resolve = createTabIconResolver(options);\n const { containerClass = `markdown-tabs` } = options;\n return (tree) => {\n visit(tree, `element`, (node) => {\n if (!hasClass(node, containerClass)) return;\n const [labelsRow] = childrenWithClass(node, `${containerClass}-labels`);\n const [panelsRow] = childrenWithClass(node, `${containerClass}-panels`);\n const labels = childrenWithClass(labelsRow, `${containerClass}-label`);\n const panels = childrenWithClass(panelsRow, `${containerClass}-panel`);\n for (const [index, label] of labels.entries()) {\n const panel = panels[index];\n const key =\n panel && `aria-label` in panel.properties\n ? `aria-label`\n : `ariaLabel`;\n const plain = panel?.properties[key];\n const first =\n label.children[0]?.type === `text` ? label.children[0] : undefined;\n // A keyword that is a defined abbreviation was wrapped by the abbr plugin, which splits the marker's text in three: `[!`, the abbreviation, and the text from `]` on. Read together they are the marker's text still.\n const [, abbr, after] = label.children;\n const term =\n abbr?.type === `element` &&\n abbr.tagName === `abbr` &&\n abbr.children.length === 1 &&\n abbr.children[0]?.type === `text`\n ? abbr.children[0]\n : undefined;\n const split =\n first?.value === `[!` &&\n abbr &&\n term &&\n after?.type === `text` &&\n after.value.startsWith(`]`)\n ? { abbr, after, lead: first.value + term.value + after.value }\n : undefined;\n const {\n icon,\n marker,\n label: text\n } = resolve(\n typeof plain === `string` ? plain : ``,\n split?.lead ?? first?.value ?? ``\n );\n if (marker && split) {\n split.after.value = split.lead.slice(marker.length);\n // A label that is only a marker reads as its keyword, which stays the abbreviation it is; otherwise the abbreviation goes with the marker.\n const only = label.children.length === 3 && split.after.value === ``;\n label.children.splice(\n 0,\n 3,\n ...(only ? [split.abbr] : []),\n ...(split.after.value ? [split.after] : [])\n );\n if (panel) panel.properties[key] = text;\n } else if (marker && first) {\n // A label that is only a marker reads as its keyword; one with markup after the marker keeps just that.\n first.value =\n first.value.slice(marker.length) ||\n (label.children.length === 1 ? text : ``);\n if (first.value === ``) label.children.shift();\n if (panel) panel.properties[key] = text;\n }\n if (icon) {\n // hast's types have no `raw` node without mdast-util-to-hast's augmentation, so the children are widened to take one.\n const children: Array<{ type: string; value?: string }> =\n label.children;\n children.unshift({ type: `raw`, value: tabIconMarkup(icon) });\n }\n }\n });\n };\n};\n"],"mappings":";;;AAWA,MAAM,YAAY,MAAkC,SAA0B;CAC5E,IAAI,MAAM,SAAS,WAAW,OAAO;CACrC,MAAM,QAAQ,KAAK,WAAW,aAAa,KAAK,WAAW;CAC3D,OAAO,MAAM,QAAQ,KAAK,IACtB,MAAM,SAAS,IAAI,IACnB,OAAO,UAAU,YAAY,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,IAAI;AACjE;AAGA,MAAM,qBACJ,QACA,UAEC,QAAQ,YAAY,CAAC,EAAA,CAAG,QAAQ,UAC/B,SAAS,OAAO,IAAI,CACtB;;;;AAKF,MAAa,kBACX,UAAU,CAAC,MACR;CACH,MAAM,UAAU,sBAAsB,OAAO;CAC7C,MAAM,EAAE,iBAAiB,oBAAoB;CAC7C,QAAQ,SAAS;EACf,MAAM,MAAM,YAAY,SAAS;GAC/B,IAAI,CAAC,SAAS,MAAM,cAAc,GAAG;GACrC,MAAM,CAAC,aAAa,kBAAkB,MAAM,GAAG,eAAe,QAAQ;GACtE,MAAM,CAAC,aAAa,kBAAkB,MAAM,GAAG,eAAe,QAAQ;GACtE,MAAM,SAAS,kBAAkB,WAAW,GAAG,eAAe,OAAO;GACrE,MAAM,SAAS,kBAAkB,WAAW,GAAG,eAAe,OAAO;GACrE,KAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,GAAG;IAC7C,MAAM,QAAQ,OAAO;IACrB,MAAM,MACJ,SAAS,gBAAgB,MAAM,aAC3B,eACA;IACN,MAAM,QAAQ,OAAO,WAAW;IAChC,MAAM,QACJ,MAAM,SAAS,EAAE,EAAE,SAAS,SAAS,MAAM,SAAS,KAAK,KAAA;IAE3D,MAAM,GAAG,MAAM,SAAS,MAAM;IAC9B,MAAM,OACJ,MAAM,SAAS,aACf,KAAK,YAAY,UACjB,KAAK,SAAS,WAAW,KACzB,KAAK,SAAS,EAAE,EAAE,SAAS,SACvB,KAAK,SAAS,KACd,KAAA;IACN,MAAM,QACJ,OAAO,UAAU,QACjB,QACA,QACA,OAAO,SAAS,UAChB,MAAM,MAAM,WAAW,GAAG,IACtB;KAAE;KAAM;KAAO,MAAM,MAAM,QAAQ,KAAK,QAAQ,MAAM;IAAM,IAC5D,KAAA;IACN,MAAM,EACJ,MACA,QACA,OAAO,SACL,QACF,OAAO,UAAU,WAAW,QAAQ,IACpC,OAAO,QAAQ,OAAO,SAAS,EACjC;IACA,IAAI,UAAU,OAAO;KACnB,MAAM,MAAM,QAAQ,MAAM,KAAK,MAAM,OAAO,MAAM;KAElD,MAAM,OAAO,MAAM,SAAS,WAAW,KAAK,MAAM,MAAM,UAAU;KAClE,MAAM,SAAS,OACb,GACA,GACA,GAAI,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,GAC3B,GAAI,MAAM,MAAM,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,CAC3C;KACA,IAAI,OAAO,MAAM,WAAW,OAAO;IACrC,OAAO,IAAI,UAAU,OAAO;KAE1B,MAAM,QACJ,MAAM,MAAM,MAAM,OAAO,MAAM,MAC9B,MAAM,SAAS,WAAW,IAAI,OAAO;KACxC,IAAI,MAAM,UAAU,IAAI,MAAM,SAAS,MAAM;KAC7C,IAAI,OAAO,MAAM,WAAW,OAAO;IACrC;IACA,IAAI,MAIF,MADQ,SACC,QAAQ;KAAE,MAAM;KAAO,OAAO,cAAc,IAAI;IAAE,CAAC;GAEhE;EACF,CAAC;CACH;AACF"}
@@ -0,0 +1,46 @@
1
+ /*
2
+ Tab icons — default stylesheet
3
+ ------------------------------
4
+ All rules live inside @layer markdown-tab-icons so any unlayered consumer
5
+ CSS overrides them without needing !important.
6
+
7
+ An icon fills a square as tall as the label's capital letters (1cap), its
8
+ drawing fitted inside, so it scales with the label's font. The square has an
9
+ explicit width because browsers leave an <svg> of auto width out of the
10
+ label's own width, which ran the text into its padding. Icons with light and dark
11
+ variants render both, marked data-scheme="light" and "dark"; these rules
12
+ show one by the reader's preferred color scheme. A site with its own theme
13
+ switch can show them by it instead, unlayered, e.g.:
14
+
15
+ :root[data-theme="light"] .markdown-tab-icon[data-scheme="light"],
16
+ :root[data-theme="dark"] .markdown-tab-icon[data-scheme="dark"] {
17
+ display: revert;
18
+ }
19
+
20
+ :root[data-theme="light"] .markdown-tab-icon[data-scheme="dark"],
21
+ :root[data-theme="dark"] .markdown-tab-icon[data-scheme="light"] {
22
+ display: none;
23
+ }
24
+ */
25
+
26
+ @layer markdown-tab-icons {
27
+ .markdown-tab-icon {
28
+ flex: none;
29
+ inline-size: 1cap;
30
+ block-size: 1cap;
31
+ }
32
+
33
+ .markdown-tab-icon[data-scheme="dark"] {
34
+ display: none;
35
+ }
36
+
37
+ @media (prefers-color-scheme: dark) {
38
+ .markdown-tab-icon[data-scheme="light"] {
39
+ display: none;
40
+ }
41
+
42
+ .markdown-tab-icon[data-scheme="dark"] {
43
+ display: revert;
44
+ }
45
+ }
46
+ }
package/package.json CHANGED
@@ -1,11 +1,46 @@
1
1
  {
2
2
  "name": "@mirrordown/remd-tab-icons",
3
- "version": "0.0.0",
4
3
  "description": "A rehype plugin to add icons to tab labels: matched from the label, or named with a [!keyword] marker.",
4
+ "version": "0.1.1",
5
5
  "license": "MIT",
6
6
  "author": "Drake Costa <drake@saeris.io> (https://saeris.gg)",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/mirrordown/mirrordown.git"
10
+ },
11
+ "style": "./dist/tab-icons.css",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "development": "./src/index.ts",
19
+ "types": "./dist/index.d.mts",
20
+ "import": "./dist/index.mjs"
21
+ },
22
+ "./*.css": "./dist/*.css"
23
+ },
24
+ "dependencies": {
25
+ "@mirrordown/core": "^0.2.0",
26
+ "unist-util-visit": "^5.1.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/hast": "^3.0.4",
30
+ "unified": "^11.0.0"
31
+ },
32
+ "peerDependencies": {
33
+ "unified": "^11.0.0"
34
+ },
35
+ "engines": {
36
+ "node": ">=24.0.0"
37
+ },
38
+ "bumpy": {
39
+ "publishCommand": [
40
+ "node ../../scripts/sync-jsr-version.mjs",
41
+ "node ../../scripts/npm-publish.mjs",
42
+ "node ../../scripts/jsr-resolve-deps.mjs",
43
+ "node ../../scripts/jsr-publish.mjs"
44
+ ]
10
45
  }
11
- }
46
+ }