Skip to main content
Glama
MarkdownRenderer.tsx2 kB
import { getContent, getContentNodeByKeyPath, getMarkdownMetadata, } from '@intlayer/core'; import type { ContentNode, KeyPath, LocalesValues } from '@intlayer/types'; import type { Component, JSX } from 'solid-js'; import { useEditedContentRenderer } from '../editor/useEditedContentRenderer'; import { useMarkdown } from './MarkdownProvider'; type MarkdownRendererProps = { dictionaryKey: string; keyPath: KeyPath[]; locale?: LocalesValues; children: string; }; export const MarkdownRenderer: Component<MarkdownRendererProps> = (props) => { const { renderMarkdown } = useMarkdown(); const editedContentContext = useEditedContentRenderer({ dictionaryKey: props.dictionaryKey, keyPath: props.keyPath, children: props.children, }); if (typeof editedContentContext !== 'string') { const transformedEditedContent = getContent( editedContentContext, { dictionaryKey: props.dictionaryKey, keyPath: props.keyPath, }, props.locale ); if (typeof transformedEditedContent !== 'string') { console.error( `Incorrect Markdown content. Edited Markdown content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}` ); return renderMarkdown(props.children); } return renderMarkdown(transformedEditedContent); } return renderMarkdown(editedContentContext); }; type MarkdownMetadataRendererProps = MarkdownRendererProps & { metadataKeyPath: KeyPath[]; }; export const MarkdownMetadataRenderer: Component< MarkdownMetadataRendererProps > = (props) => { const editedContentContext = useEditedContentRenderer({ dictionaryKey: props.dictionaryKey, keyPath: props.keyPath, children: props.children, }); const metadata = getMarkdownMetadata(editedContentContext); const metadataEl = getContentNodeByKeyPath( metadata as ContentNode, props.metadataKeyPath ); return metadataEl as JSX.Element; };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server