Skip to content
rehype-code-group

Options

The default configuration is intentionally usable without setup. Override only the ownership, diagnostics, or naming behavior your pipeline needs.

options.ts
type RehypeCodeGroupOptions = {
  assets?:
    | "inline"
    | "none"
    | { mode: "inline"; nonce?: string }
    | {
        mode: "external";
        nonce?: string;
        scriptSrc: string;
        stylesheetHref: string;
      };
  customClassNames?: Partial<ClassNames>;
  diagnostics?: "warn" | "error" | "silent";
  idPrefix?: string;
  labelResolver?: (label: string) => string;
};

assets

Default: "inline".

ValueBehavior
"inline"Insert styles and a classic client script only when a group exists
"none"Emit markup only
{ mode: "inline", nonce }Inline assets with a CSP nonce
{ mode: "external", ... }Emit external asset elements using your URLs

customClassNames

Add classes for codeGroupClass, tabContainerClass, tabClass, activeTabClass, blockContainerClass, and activeBlockClass. Defaults remain present as stable client hooks.

diagnostics

Default: "warn".

ValueInvalid sourceBuild result
"warn"PreservedVFile message
"error"PreservedProcessing fails
"silent"PreservedNo diagnostic

idPrefix

Default: "rcg". Generated IDs are deterministic within each transformation. Set a unique prefix when separately compiled fragments will be combined in one document.

labelResolver

Default: commonLabelResolver. Receives each display label and returns the rendered label. Use fullEmojiResolver from rehype-code-group/emoji for the complete shortcode catalog.

Browser client

browser-client.ts
import {
  ,
  type ,
} from "rehype-code-group/client";
 
const cleanupArrow
= ();
();

Repeated calls for the same root return the same cleanup function. The client automatically initializes when imported in a browser.

Package-manager options

package-managers.ts
type PackageManagerOptions = {
  diagnostics?: "warn" | "error" | "silent";
  packageManagers?: Array<"npm" | "pnpm" | "yarn" | "bun">;
};
Public subpaths
  • rehype-code-group — rehype plugin and option types
  • rehype-code-group/remark — fence-metadata helper
  • rehype-code-group/package-managers — npm command converter
  • rehype-code-group/client — browser enhancer and event types
  • rehype-code-group/styles.css — authoritative stylesheet
  • rehype-code-group/emoji — complete optional emoji resolver