remark-flexible-code-titles
Version:
Remark plugin to add title or/and container for code blocks with customizable properties in markdown
55 lines (54 loc) • 1.42 kB
TypeScript
import type { Plugin } from "unified";
import type { Root, Data, BlockContent, Parent } from "mdast";
interface ContainerData extends Data {
}
interface Container extends Parent {
/**
* Node type of mdast Mark.
*/
type: "container";
/**
* Children of paragraph.
*/
children: BlockContent[];
/**
* Data associated with the mdast paragraph.
*/
data?: ContainerData | undefined;
}
declare module "mdast" {
interface BlockContentMap {
container: Container;
}
interface RootContentMap {
container: Container;
}
}
type RestrictedRecord = Record<string, unknown> & {
className?: never;
};
type PropertyFunction = (language?: string, title?: string) => RestrictedRecord;
export type CodeTitleOptions = {
title?: boolean;
titleTagName?: string;
titleClassName?: string;
titleProperties?: PropertyFunction;
container?: boolean;
containerTagName?: string;
containerClassName?: string;
containerProperties?: PropertyFunction;
handleMissingLanguageAs?: string;
tokenForSpaceInTitle?: string;
};
/**
*
* This plugin adds a title element before the code element, if the title exists in the markdown code block;
* and wraps them in a container.
*
* for example:
* ```javascript:title.js
* // some js code
* ```
*/
export declare const plugin: Plugin<[CodeTitleOptions?], Root>;
export default plugin;