import { HTMLComponents } from "../html/HTMLComponentTypes.js"; import { MarkdownProviderOptions } from "./MarkdownProvider.js"; import { ParsedMarkdown } from "./processor.js"; import { FC, HTMLAttributes, JSX, ReactNode } from "react"; /** * Props for rendering markdown content. * * @example * ```tsx * const props: RenderMarkdownProps = { * components: { * h1: ({ children }) =>

{children}

, * p: ({ children }) =>

{children}

, * }, * wrapper: ({ children }) =>
{children}
, * options: { * forceBlock: true, * preserveFrontmatter: false, * tagfilter: true, * }, * }; * ``` */ export type RenderMarkdownProps = MarkdownProviderOptions & { /** * Component overrides for HTML tags. * Allows you to customize how specific HTML elements are rendered. * Only used if not wrapped in a MarkdownProvider. * * @example * ```tsx * components={{ * h1: ({ children }) =>

{children}

, * a: ({ href, children }) => {children}, * }} * ``` */ components?: HTMLComponents<'permissive', {}>; /** * Wrapper element or component to be used when there are multiple children. * Only used if not wrapped in a MarkdownProvider. * * @example * ```tsx * wrapper={({ children }) =>
{children}
} * ``` */ wrapper?: FC>; }; /** * Renders markdown content to JSX with the provided components and options. * * This function does not use context from MarkdownProvider. Use `useMarkdownRenderer` * hook if you want to leverage provider context. * * @param content - The markdown string to render * @param props - Configuration options for rendering * @param props.components - Component overrides for HTML tags * @param props.wrapper - Wrapper component for multiple children * @returns JSX element representing the rendered markdown * * @example * ```tsx * import { renderMarkdown } from '@intlayer/react-intlayer/markdown'; * * const markdown = '# Hello World\n\nThis is **bold** text.'; * const jsx = renderMarkdown(markdown, { * components: { * h1: ({ children }) =>

{children}

, * }, * forceBlock: true, * }); * ``` */ export declare const renderMarkdown: (content: string | ParsedMarkdown, { components, wrapper, forceBlock, forceInline, preserveFrontmatter, tagfilter }?: RenderMarkdownProps) => JSX.Element; /** * Hook that returns a function to render markdown content. * * This hook considers the configuration from the `MarkdownProvider` context if available, * falling back to the provided props or default behavior. * * @param props - Optional configuration that will override context values * @param props.components - Component overrides for HTML tags (overrides context) * @param props.wrapper - Wrapper component (overrides context) * @returns A function that takes markdown content and returns JSX * * @example * ```tsx * import { useMarkdownRenderer } from '@intlayer/react-intlayer/markdown'; * * function MyComponent() { * const renderMarkdown = useMarkdownRenderer({ * components: { * h1: ({ children }) =>

{children}

, * }, * }); * * return ( *
* {renderMarkdown('# Hello\n\nThis is **markdown**')} *
* ); * } * ``` * * @example * ```tsx * // With MarkdownProvider context * function App() { * return ( * * * * ); * } * ``` */ export declare const useMarkdownRenderer: ({ components, wrapper, forceBlock, forceInline, preserveFrontmatter, tagfilter }?: RenderMarkdownProps) => (content: string | ParsedMarkdown) => string | number | bigint | boolean | JSX.Element | Iterable | Promise; /** * Props for the MarkdownRenderer component. * * @example * ```tsx * const props: MarkdownRendererProps = { * children: '# Hello World\n\nThis is **bold** text.', * components: { * h1: ({ children }) =>

{children}

, * }, * wrapper: ({ children }) =>
{children}
, * forceBlock: true, * }; * ``` */ export type MarkdownRendererProps = RenderMarkdownProps & { /** * The markdown content to render as a string. * * @example * ```tsx * * {`# Title\n\nParagraph with **bold** text.`} * * ``` */ children: string | ParsedMarkdown; /** * Custom render function for markdown. * If provided, it will overwrite context and default rendering. * * @param markdown - The markdown string to render * @param options - Optional rendering options * @returns React node representing the rendered markdown * * @example * ```tsx * { * // Custom rendering logic * return
; * }} * > * {markdownContent} * * ``` */ renderMarkdown?: (markdown: string | ParsedMarkdown, options?: { components?: HTMLComponents<'permissive', {}>; wrapper?: FC; forceBlock?: boolean; forceInline?: boolean; preserveFrontmatter?: boolean; tagfilter?: boolean; }) => ReactNode | Promise; }; /** * React component that renders markdown content to JSX. * * This component uses the `renderMarkdown` function from the `MarkdownProvider` context * if available. Otherwise, it falls back to the default compiler with provided components * and options. You can also provide a custom `renderMarkdown` function prop to override * all rendering behavior. * * @example * ```tsx * import { MarkdownRenderer } from '@intlayer/react-intlayer/markdown'; * * function MyComponent() { * return ( * * {`# Hello World * * This is a paragraph with **bold** and *italic* text. * * - List item 1 * - List item 2`} * * ); * } * ``` * * @example * ```tsx * // With custom components *

{children}

, * a: ({ href, children }) => ( * * {children} * * ), * }} * forceBlock={true} * > * {markdownContent} *
* ``` * * @example * ```tsx * // With MarkdownProvider context * function App() { * return ( * * * {markdownContent} * * * ); * } * ``` */ export declare const MarkdownRenderer: FC; //# sourceMappingURL=MarkdownRenderer.d.ts.map