export function heading(level, text) {
    return `${"#".repeat(level)} ${text}`;
}
export function codeFence(code, lang = "ts") {
    const matches = code.match(/`+/g) ?? [];
    const longest = matches.reduce((m, s) => Math.max(m, s.length), 0);
    const fence = "`".repeat(Math.max(3, longest + 1));
    return `${fence}${lang}\n${code.trimEnd()}\n${fence}`;
}
export function bold(text) {
    return `**${text}**`;
}
export function escapeTableCell(value) {
    return value.replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
}
export function markdownTable(headers, rows) {
    const headerRow = `| ${headers.join(" | ")} |`;
    const separator = `|${headers.map(() => "---").join("|")}|`;
    const dataRows = rows.map((row) => `| ${row.map(escapeTableCell).join(" | ")} |`);
    return [headerRow, separator, ...dataRows].join("\n");
}
export function section(...parts) {
    return parts.filter(Boolean).join("\n\n");
}
