"use client"; import * as React from "react"; import ReactMarkdown, { type Components } from "react-markdown"; import remarkGfm from "remark-gfm"; import { CopyButton } from "@/components/ui/misc"; import { cn } from "@/lib/utils"; /** * Lightweight Markdown renderer for public pages (share view). GFM, monospace code blocks with a * copy button, no syntax highlighting, no raw HTML. */ function textOf(node: React.ReactNode): string { if (node == null || typeof node === "boolean") return ""; if (typeof node === "string" || typeof node === "number") return String(node); if (Array.isArray(node)) return node.map(textOf).join(""); if (React.isValidElement<{ children?: React.ReactNode }>(node)) return textOf(node.props.children); return ""; } function Pre({ children }: React.HTMLAttributes) { const codeEl = React.Children.toArray(children).find((c) => React.isValidElement(c)) as React.ReactElement<{ className?: string; children?: React.ReactNode }> | undefined; const lang = codeEl?.props.className?.match(/language-([\w+-]+)/)?.[1]; const raw = textOf(codeEl?.props.children ?? children).replace(/\n$/, ""); return (
{lang ?? "code"}
        {codeEl ? codeEl.props.children : children}
      
); } const components: Components = { pre: Pre, a: ({ href, children }) => ( {children} ), table: ({ children }) => (
{children}
), }; export function SimpleMarkdown({ children, className }: { children: string; className?: string }) { return (
{children}
); }