"use client"; /** * Web-adapted Markdown renderer. * * The terminal Markdown (src/components/Markdown.tsx) uses marked + Ink's * / to render tokenised markdown as coloured ANSI output. * This web version uses react-markdown + remark-gfm + rehype-highlight, which * are already present in the web package, to render proper HTML with Tailwind * prose styles. * * Props are intentionally compatible with the terminal version so callers can * swap between them via the platform conditional. */ import * as React from "react"; import { useMemo } from "react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import { cn } from "@/lib/utils"; // ─── Types ──────────────────────────────────────────────────────────────────── export interface MarkdownProps { /** Markdown source string — matches the terminal component's children prop. */ children: string; /** When true, render all text as visually dimmed (muted colour). */ dimColor?: boolean; /** Extra class names applied to the prose wrapper. */ className?: string; } // ─── Inline code / pre renderers ───────────────────────────────────────────── function InlineCode({ children }: { children?: React.ReactNode }) { return ( {children} ); } interface PreProps { children?: React.ReactNode; } function Pre({ children }: PreProps) { return (
      {children}
    
); } // ─── Component ──────────────────────────────────────────────────────────────── export function Markdown({ children, dimColor = false, className }: MarkdownProps) { // Memoised to avoid re-parsing on every parent render. const content = useMemo(() => children, [children]); return (
{codeChildren} ); } return {codeChildren}; }, pre: ({ children: preChildren }) =>
{preChildren}
, }} > {content}
); } // ─── Table component (matches MarkdownTable.tsx surface) ───────────────────── export interface MarkdownTableProps { headers: string[]; rows: string[][]; className?: string; } export function MarkdownTable({ headers, rows, className }: MarkdownTableProps) { return (
{headers.map((h, i) => ( ))} {rows.map((row, ri) => ( {row.map((cell, ci) => ( ))} ))}
{h}
{cell}
); }