{element}
);
}
if (node.bold) element = {element};
if (node.italic) element = {element};
if (node.underline) element = {element};
if (node.strikethrough) element = {renderInline(node.children)}); case "code": return (
{renderInline(node.children)}
);
case "image": {
const image = node.image;
if (!image?.url) return null;
return (
{renderInline((node as { children?: readonly CmsInlineNode[] }).children)}
); } } /* --------------------------------------------------------------------------- ENTRY POINT ------------------------------------------------------------------------ */ /** A blank paragraph separates plain-text bodies into paragraphs. */ function paragraphsOf(value: string): string[] { return value .split(/\n{2,}/) .map((paragraph) => paragraph.trim()) .filter(Boolean); } export interface RichTextProps { /** A Strapi blocks value, a plain string, or nothing at all. */ value: CmsRichText | undefined; className?: string; } /** * Renders whichever of the two shapes the field turned out to be, and nothing * at all when it is empty - so a body that has not been written yet leaves no * stray heading or empty box behind. */ export function RichText({ value, className }: RichTextProps) { if (!value) return null; const stack = `flex flex-col gap-md${className ? ` ${className}` : ""}`; if (typeof value === "string") { const paragraphs = paragraphsOf(value); if (paragraphs.length === 0) return null; return ({paragraph}
))}