react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
56 lines (55 loc) • 2.5 kB
TypeScript
import { HTMLComponents } from "../html/HTMLComponentTypes.js";
import { ParsedMarkdown } from "./processor.js";
import { FC, HTMLAttributes, PropsWithChildren, ReactNode } from "react";
//#region src/markdown/MarkdownProvider.d.ts
type MarkdownProviderOptions = {
/** Forces the compiler to always output content with a block-level wrapper. */forceBlock?: boolean; /** Forces the compiler to always output content with an inline wrapper. */
forceInline?: boolean; /** Whether to preserve frontmatter in the markdown content. */
preserveFrontmatter?: boolean; /** Whether to use the GitHub Tag Filter for security. */
tagfilter?: boolean;
};
type MarkdownContextValue = {
components?: HTMLComponents<'permissive', {}>;
renderMarkdown: (markdown: string | ParsedMarkdown, options?: MarkdownProviderOptions, components?: HTMLComponents<'permissive', {}>, wrapper?: FC<HTMLAttributes<HTMLElement>>) => ReactNode | Promise<ReactNode>;
};
type MarkdownProviderProps = PropsWithChildren<MarkdownProviderOptions & {
components?: HTMLComponents<'permissive', {}>;
wrapper?: FC<HTMLAttributes<HTMLElement>>;
renderMarkdown?: (markdown: string | ParsedMarkdown, options?: MarkdownProviderOptions, components?: HTMLComponents<'permissive', {}>, wrapper?: FC<HTMLAttributes<HTMLElement>>) => ReactNode | Promise<ReactNode>;
}>;
/**
* Returns the raw `MarkdownProvider` context value — the active
* `renderMarkdown` function plus any provider-level component overrides.
* Returns `undefined` when called outside a `<MarkdownProvider>`.
* Prefer `useMarkdownRenderer` for most use cases; use this hook only when
* you need direct access to the context object itself.
*/
declare const useMarkdownContext: () => MarkdownContextValue;
/**
* Provider for the MarkdownRenderer component.
*
* It will provide the `renderMarkdown` function to the context, which can be used to render markdown.
*
* ```tsx
* const content = useIntlayer('app');
*
* return (
* <div>
* {content.markdown} // Will be rendered with the components and options provided to the MarkdownProvider
* </div>
* );
* ```
*
* @example
* ```tsx
* <MarkdownProvider components={{ h1: CustomHeading }}>
* <MarkdownRenderer>
* {markdownContent}
* </MarkdownRenderer>
* </MarkdownProvider>
* ```
*/
declare const MarkdownProvider: FC<MarkdownProviderProps>;
//#endregion
export { MarkdownProvider, MarkdownProviderOptions, useMarkdownContext };
//# sourceMappingURL=MarkdownProvider.d.ts.map