UNPKG

react-intlayer

Version:

Easily internationalize i18n your React applications with type-safe multilingual content management.

62 lines 1.6 kB
"use client"; import { getContent, getContentNodeByKeyPath, getMarkdownMetadata } from "@intlayer/core"; import { useEditedContentRenderer } from "../editor/useEditedContentRenderer.mjs"; import { useMarkdownContext } from "./MarkdownProvider.mjs"; const MarkdownRenderer = ({ dictionaryKey, keyPath, children, locale }) => { const { renderMarkdown } = useMarkdownContext(); const editedContentContext = useEditedContentRenderer({ dictionaryKey, keyPath, children }); if (typeof editedContentContext !== "string") { const transformedEditedContent = getContent( editedContentContext, { dictionaryKey, keyPath }, locale ); if (typeof transformedEditedContent !== "string") { console.error( `Incorrect Markdown content. Edited Markdown content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}` ); return renderMarkdown(children); } return renderMarkdown(transformedEditedContent); } return renderMarkdown(editedContentContext); }; const MarkdownMetadataRenderer = ({ dictionaryKey, keyPath, children, metadataKeyPath }) => { const editedContentContext = useEditedContentRenderer({ dictionaryKey, keyPath, children }); const metadata = getMarkdownMetadata(editedContentContext); const metadataEl = getContentNodeByKeyPath( metadata, metadataKeyPath ); return metadataEl; }; export { MarkdownMetadataRenderer, MarkdownRenderer }; //# sourceMappingURL=MarkdownRenderer.mjs.map