import { useResolvedUrl, parseUrlScheme } from './useResolvedUrl'; import { CodeBlockPlaceholder } from './CodeBlockPlaceholder'; export interface MarkdownFigureProps { src?: string; alt?: string; caption: string; className?: string; artifactRunId?: string; } /** * Markdown figure component for images with captions. * Wraps the image in a
element with a
. * * Usage in markdown: ![alt text](image-url "Caption text") */ export function MarkdownFigure({ src, alt, caption, className, artifactRunId, }: MarkdownFigureProps) { const rawSrc = src || ''; const { scheme } = parseUrlScheme(rawSrc); // For standard URLs, render directly if (scheme === 'standard') { return (
{alt}
{caption}
); } // For artifact: and image: URLs, use the resolver return ( ); } /** * Internal component for figures that need async URL resolution */ function ResolvedFigure({ rawSrc, alt, caption, artifactRunId, className, }: { rawSrc: string; alt?: string; caption: string; artifactRunId?: string; className?: string; }) { const { url, isLoading, error, retry } = useResolvedUrl({ rawUrl: rawSrc, artifactRunId, disposition: 'inline', }); if (isLoading) { return ; } if (error) { return ( ); } if (!url) { return null; } return (
{alt}
{caption}
); }