"use client"; import ReactMarkdown, { defaultUrlTransform, type Components } from "react-markdown"; import remarkBreaks from "remark-breaks"; import remarkGfm from "remark-gfm"; import { cn } from "@/lib/utils"; const INLINE_ELEMENTS = ["strong", "em", "del", "code", "a", "br"]; const BLOCK_ELEMENTS = ["p", "ul", "ol", "li", ...INLINE_ELEMENTS]; type ClarificationMarkdownProps = { children: string; variant: "block" | "inline"; linkBehavior?: "interactive" | "passive"; className?: string; }; function markdownComponents(linkBehavior: "interactive" | "passive"): Components { return { p: ({ children }) =>

{children}

, ul: ({ children }) => ( ), ol: ({ children }) => (
    {children}
), li: ({ children }) =>
  • {children}
  • , code: ({ children, className }) => { const isBlock = className?.startsWith("language-") || String(children).includes("\n"); if (isBlock) return {children}; return ( {children} ); }, a: ({ children, href }) => { const isWebLink = href ? /^https?:\/\//i.test(href) : false; if (linkBehavior === "passive" || !isWebLink) { return {children}; } return ( {children} ); }, }; } export function ClarificationMarkdown({ children, variant, linkBehavior = "interactive", className, }: ClarificationMarkdownProps) { const content = ( {children} ); if (variant === "inline") { return {content}; } return
    {content}
    ; } export type { ClarificationMarkdownProps };