UNPKG

harden-react-markdown-urls

Version:

🛡️ Secure wrapper for react-markdown that sanitizes link and image URLs using rehype-harden-urls. Do complex things, the simple way.

26 lines (25 loc) 1.08 kB
import type { ComponentType } from "react"; import type { Options } from "react-markdown"; import { type RehypeHardenUrlsOptions } from "rehype-harden-urls"; type WithHardenedProps<T extends { rehypePlugins?: Options["rehypePlugins"]; }> = T & { /** * Options specific to rehype-harden-urls. These override the defaultHardenOptions. * {@link RehypeHardenUrlsOptions} */ hardenedOptions?: RehypeHardenUrlsOptions; }; /** * A Higher-Order Component (HOC) that wraps a react-markdown-like component * and automatically injects the rehype-harden-urls plugin for security. * * @param MarkdownComponent The base react-markdown component to wrap. * @param defaultHardenOptions Default options for the hardening plugin. * {@link RehypeHardenUrlsOptions} * @returns A new component with security-hardened link URLs. */ export declare const hardenReactMarkdown: <T extends { rehypePlugins?: Options["rehypePlugins"]; }>(MarkdownComponent: ComponentType<T>, defaultHardenOptions?: RehypeHardenUrlsOptions) => ComponentType<WithHardenedProps<T>>; export {};