react-remarkify
Version:
A simple React.js utility to convert Markdown into React components.
40 lines (39 loc) • 1.13 kB
TypeScript
import { Options as RemarkRehypeOptions } from "mdast-util-to-hast";
import { ComponentType, JSX } from "react";
import { Options as RemarkParseOptions } from "remark-parse";
import { PluggableList } from "unified";
export type CommonProps = {
rehypePlugins?: PluggableList;
rehypeReactOptions?: RehypeReactOptions;
remarkParseOptions?: RemarkParseOptions;
remarkPlugins?: PluggableList;
remarkToRehypeOptions?: RemarkRehypeOptions;
components?: Components;
onError?: (err: Error) => void;
};
export type Components = {
[Key in keyof JSX.IntrinsicElements]?: ComponentType<JSX.IntrinsicElements[Key] & {
node?: Element;
}> | keyof JSX.IntrinsicElements;
};
export type UseRemarkOptions = CommonProps & {
markdown: string;
};
export type RehypeReactOptions = {
components?: Partial<Components>;
};
export type RemarkProps = CommonProps & {
children: string;
};
type Success<T> = {
success: true;
data: T;
error: null;
};
type Failure<E> = {
success: false;
data: null;
error: E;
};
export type Result<T, E = Error> = Success<T> | Failure<E>;
export {};