@md2docx/react-markdown
Version:
A modern, SSR-friendly React Markdown renderer that preserves the MDAST tree for reuse (e.g., mdast2docx), supports full JSX children, unified plugins, and component overrides.
66 lines (65 loc) • 2.26 kB
TypeScript
import { FC, HTMLProps, JSX } from "react";
import { type Options } from "remark-rehype";
import { PluggableList } from "unified";
import { Root } from "mdast";
import { Element, Root as HastRoot, Properties } from "hast";
export declare const handleAriaAndDataProps: (properties: Properties) => {
[k: string]: string | number | boolean | (string | number)[] | null | undefined;
};
export declare const uuid: () => `${string}-${string}-${string}-${string}-${string}`;
export type IntrinsicProps = JSX.IntrinsicElements[keyof JSX.IntrinsicElements];
/**
* Extended component props to support custom HTML components
* and HAST Element reference.
*/
export type ComponentProps = IntrinsicProps & {
node: Element;
};
export type AstArrayElement = {
mdast: Root;
hast: HastRoot;
};
export type AstRef = {
current?: AstArrayElement[];
};
/**
* Props accepted by the main `<Md />` component for rendering Markdown.
*/
export interface MdxProps extends HTMLProps<HTMLDivElement> {
/**
* Optional wrapper element. Defaults to `<div>` if additional props are passed, otherwise uses `Fragment`.
*/
wrapper?: keyof JSX.IntrinsicElements;
/**
* Optional `remark` plugins used during markdown parsing.
*/
remarkPlugins?: PluggableList;
/**
* Optional `rehype` plugins used during markdown-to-HTML conversion.
*/
rehypePlugins?: PluggableList;
/**
* Options passed to `remark-rehype` for controlling transformation.
*/
remarkRehypeOptions?: Options;
/**
* Optional reference to access the parsed MDAST and HAST trees.
*/
astRef?: AstRef;
/**
* Custom React components to override specific HTML tags.
*/
components?: Partial<Record<keyof JSX.IntrinsicElements, FC<ComponentProps>>>;
/**
* If true, skips raw HTML rendering in markdown content.
*/
skipHtml?: boolean;
}
export interface MdProps extends MdxProps {
children?: string;
}
/**
* Internal component that parses markdown string into MDAST and HAST,
* and renders it using the `El` recursive renderer.
*/
export declare const Markdown: ({ children, remarkPlugins, rehypePlugins, remarkRehypeOptions, astRef, components, skipHtml, }: MdProps) => JSX.Element;