Skip to content

Installation

Terminal window
pnpm add rehype-gfm-components

There are two ways to use the plugin — as a Starlight plugin (recommended if you’re using Starlight) or as a raw rehype plugin for any framework with rehype access.

The Starlight adapter handles everything for you: icon loading, tab script injection, and CSS registration.

  1. Add the plugin to your Starlight config

    astro.config.mjs
    import { defineConfig } from "astro/config";
    import starlight from "@astrojs/starlight";
    import starlightGfmComponents from "rehype-gfm-components/starlight";
    export default defineConfig({
    integrations: [
    starlight({
    title: "My Docs",
    plugins: [starlightGfmComponents()],
    }),
    ],
    });

    That’s it. The adapter registers the rehype plugin, loads Starlight’s icon SVGs, injects the tab-switching script, and adds the bundled CSS.

  2. Write GFM Markdown

    Start using HTML comment markers in your .md files. No imports, no MDX, no file renaming.

  3. Run your dev server

    Terminal window
    pnpm dev

    Your content renders as rich components in Starlight and stays readable on GitHub.

For any framework that exposes rehype — Astro without Starlight, Next.js, or a custom unified pipeline.

  1. Add the plugin to your markdown config

    // astro.config.mjs (without Starlight)
    import { rehypeGfmComponents } from "rehype-gfm-components";
    export default defineConfig({
    markdown: {
    rehypePlugins: [rehypeGfmComponents],
    },
    });

    Or in a unified pipeline:

    import { unified } from "unified";
    import remarkParse from "remark-parse";
    import remarkGfm from "remark-gfm";
    import remarkRehype from "remark-rehype";
    import rehypeRaw from "rehype-raw";
    import { rehypeGfmComponents } from "rehype-gfm-components";
    import rehypeStringify from "rehype-stringify";
    const result = await unified()
    .use(remarkParse)
    .use(remarkGfm)
    .use(remarkRehype, { allowDangerousHtml: true })
    .use(rehypeRaw)
    .use(rehypeGfmComponents)
    .use(rehypeStringify)
    .process(markdown);
  2. Add the CSS (if targeting Starlight’s component styles)

    astro.config.mjs
    export default defineConfig({
    integrations: [
    starlight({
    customCss: ["rehype-gfm-components/styles/starlight.css"],
    }),
    ],
    });
  3. Provide icons (optional)

    Without the Starlight adapter, icons aren’t auto-detected. You can provide them manually:

    rehypeGfmComponents({
    icons: {
    rocket: '<path d="M4.5 16.5c-1.5 ..."/>',
    },
    })

    Or skip icons entirely — components that use icon parameters will render data-gfm-icon placeholder spans that you can hydrate with your own client-side logic.

rehypeGfmComponents({
// Enable only specific transforms (default: all)
transforms: ["steps", "tabs", "filetree", "card", "cardgrid",
"linkcard", "linkcards", "linkbutton", "badge", "icon"],
// Icon SVG data — auto-detected from Starlight when using the adapter
icons: { rocket: '<path d="M1 1"/>' },
// Footnote-to-tooltip transform (default: true)
tooltips: false,
})
OptionTypeDefaultDescription
transformsstring[]allWhich transforms to enable
iconsRecord<string, string>auto-detectIcon name to SVG path string map
tooltipsbooleantrueConvert GFM footnotes to inline tooltips
  • Node.js 20+ (LTS)
  • @astrojs/starlight >= 0.30.0 (for the Starlight adapter, optional)