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(
{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(line, key)}
) }) flushList("end") if (code !== null) out.push({(code as string[]).join("\n")})
return {p.slice(1, -1)}
return {p}
})
}