import React from "react"; import { Block } from "../types"; import { InlineMarkdown } from "./InlineMarkdown"; import { ListMarker } from "./ListMarker"; import { CodeBlock } from "./blocks/CodeBlock"; import { HtmlBlock } from "./blocks/HtmlBlock"; import { Callout } from "./blocks/Callout"; import { AlertBlock } from "./blocks/AlertBlock"; import { TableBlock } from "./blocks/TableBlock"; export const BlockRenderer: React.FC<{ block: Block; onOpenLinkedDoc?: (path: string) => void; onOpenCodeFile?: (path: string) => void; imageBaseDir?: string; onImageClick?: (src: string, alt: string) => void; onToggleCheckbox?: (blockId: string, checked: boolean) => void; checkboxOverrides?: Map; orderedIndex?: number | null; githubRepo?: string; headingAnchorId?: string; onNavigateAnchor?: (hash: string) => void; }> = ({ block, onOpenLinkedDoc, onOpenCodeFile, imageBaseDir, onImageClick, onToggleCheckbox, checkboxOverrides, orderedIndex, githubRepo, headingAnchorId, onNavigateAnchor }) => { switch (block.type) { case 'heading': { const Tag = `h${block.level || 1}` as React.ElementType; const styles = { 1: 'text-2xl font-bold mb-4 mt-6 first:mt-0 tracking-tight', 2: 'text-xl font-semibold mb-3 mt-8 text-foreground/90', 3: 'text-base font-semibold mb-2 mt-6 text-foreground/80', }[block.level || 1] || 'text-base font-semibold mb-2 mt-4'; return ( ); } case 'blockquote': { if (block.alertKind) { return ( ); } // Content may span multiple merged `>` lines. Split on blank-line // paragraph breaks so `> a\n>\n> b` renders as two

children. const paragraphs = block.content.split(/\n\n+/); return (

{paragraphs.map((para, i) => (

0 ? 'mt-2' : ''}>

))}
); } case 'list-item': { const indent = (block.level || 0) * 1.25; // 1.25rem per level const isCheckbox = block.checked !== undefined; const isChecked = checkboxOverrides?.has(block.id) ? checkboxOverrides.get(block.id)! : block.checked; const isInteractive = isCheckbox && !!onToggleCheckbox; const textClass = `text-sm leading-relaxed ${isCheckbox && isChecked ? 'text-muted-foreground line-through' : 'text-foreground/90'}`; const paragraphs = block.content.split(/\n\n+/); const inlineProps = { imageBaseDir, onImageClick, onOpenLinkedDoc, onOpenCodeFile, githubRepo, onNavigateAnchor }; return (
onToggleCheckbox!(block.id, !isChecked) : undefined} /> {paragraphs.length === 1 ? ( ) : (
{paragraphs.map((para, i) => (

0 ? 'mt-3' : ''}>

))}
)}
); } case 'code': return {}} onLeave={() => {}} isHovered={false} />; case 'table': return ( ); case 'hr': return
; case 'html': return ; case 'directive': { const kind = block.directiveKind || 'note'; return ( ); } default: return (

); } };