rehype-code-titles
Version:
Rehype plugin for parsing code blocks and adding titles to code blocks
41 lines (40 loc) • 1.6 kB
TypeScript
export default rehypeCodeTitles;
export type Root = import("hast").Root;
export type Element = import("hast").Element;
export type ElementContent = import("hast").ElementContent;
export type Visitor = import("unist-util-visit").BuildVisitor<Root, "element">;
export type Options = {
/**
* - Custom CSS class name for title div
*/
customClassName?: string | undefined;
/**
* - Character(s) used to separate language from title
*/
titleSeparator?: string | undefined;
};
/**
* @typedef {import('hast').Root} Root
* @typedef {import('hast').Element} Element
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('unist-util-visit').BuildVisitor<Root, 'element'>} Visitor
*/
/**
* @typedef {Object} Options
* @property {string} [customClassName='rehype-code-title'] - Custom CSS class name for title div
* @property {string} [titleSeparator=':'] - Character(s) used to separate language from title
*/
/**
* Rehype plugin to add title blocks to code elements.
*
* This plugin parses code block class names for a title separator and creates
* a title div before the code block.
*
* @example
* // Input: <pre><code className="language-typescript:lib/mdx.ts">...</code></pre>
* // Output: <div className="rehype-code-title">lib/mdx.ts</div><pre><code className="language-typescript">...</code></pre>
*
* @param {Options} [options] - Plugin configuration options
* @returns {function(Root): void} Transformer function
*/
declare function rehypeCodeTitles({ customClassName, titleSeparator, }?: Options): (arg0: Root) => void;