import { cn } from "@/lib/utils" // Leichtgewichtiger Markdown-Renderer (Zeilen-basiert, XSS-frei da reines JSX, // bewusst ohne externe Lib). Überschriften, Listen, fett/kursiv, `code`, Codeblöcke. // Verwandt mit dem wiki-link-Renderer in WissenView, hier aber ohne [[links]] — // gedacht für Doku-Anzeige (z. B. das KONZEPT.md eines vorbereiteten IDE-Projekts). export function Markdown({ text, className }: { text: string; className?: string }) { const lines = (text || "").split("\n") const out: React.ReactNode[] = [] let list: React.ReactNode[] = [] let code: string[] | null = null const flushList = (key: string) => { if (list.length) { out.push() list = [] } } lines.forEach((raw, i) => { const key = `l${i}` if (code !== null) { if (raw.trimEnd() === "```") { out.push(
{code.join("\n")}
) code = null } else code.push(raw) return } if (raw.trimStart().startsWith("```")) { flushList(key); code = []; return } const line = raw.trimEnd() if (!line.trim()) { flushList(key); return } const h = line.match(/^(#{1,4})\s+(.*)$/) if (h) { flushList(key) const level = h[1].length const cls = level === 1 ? "text-base font-bold mt-1 mb-2" : level === 2 ? "text-sm font-bold mt-4 mb-1.5" : "text-xs font-bold mt-3 mb-1 uppercase tracking-wide text-muted-foreground" out.push(

{inline(h[2], key)}

) return } const li = line.match(/^\s*[-*•]\s+(.*)$/) if (li) { list.push(
  • {inline(li[1], key)}
  • ) return } const ol = line.match(/^\s*\d+\.\s+(.*)$/) if (ol) { list.push(
  • {inline(ol[1], key)}
  • ) return } flushList(key) out.push(

    {inline(line, key)}

    ) }) flushList("end") if (code !== null) out.push(
    {(code as string[]).join("\n")}
    ) return
    {out}
    } // Inline: **fett**, *kursiv*, `code` — per Regex-Split, reines JSX (kein HTML-Inject). function inline(text: string, keyBase: string): React.ReactNode[] { const parts = text.split(/(\*\*[^*]+\*\*|\*[^*]+\*|`[^`]+`)/g) return parts.map((p, i) => { const key = `${keyBase}-${i}` if (/^\*\*[^*]+\*\*$/.test(p)) return {p.slice(2, -2)} if (/^\*[^*]+\*$/.test(p)) return {p.slice(1, -1)} if (/^`[^`]+`$/.test(p)) return {p.slice(1, -1)} return {p} }) }