From b9610663a68ab0530d41191ef4f5c68ea11aac69 Mon Sep 17 00:00:00 2001 From: mitchell Date: Sun, 3 May 2026 23:11:02 -0400 Subject: [PATCH] refactor: adjust markdown line wrapping --- src/render/markdown.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/render/markdown.ts b/src/render/markdown.ts index bd4d777..55cf103 100644 --- a/src/render/markdown.ts +++ b/src/render/markdown.ts @@ -49,16 +49,18 @@ export async function renderMarkdown( return Bun.wrapAnsi( color.bold(`${"#".repeat(level)} ${children}\n\n`), columns, + { trim: false }, ); }, - paragraph: (children) => Bun.wrapAnsi(`${children}\n\n`, columns), + paragraph: (children) => + Bun.wrapAnsi(`${children}\n\n`, columns - 2, { trim: false }), blockquote: (children) => { - const lines = children.split("\n"); + const lines = Bun.wrapAnsi(children, columns).split("\n"); const toRender = lines .map((line) => `${chalk.dim("> ")}${line}`) .join("\n") - .replace(/\n$/, "\n\n"); - return Bun.wrapAnsi(toRender, columns); + .concat("\n\n"); + return toRender; }, code: (children, meta) => { let toRender = children; @@ -77,10 +79,7 @@ export async function renderMarkdown( return `\`\`\`${chalk.blue(meta?.language ?? "")}\n${toRender}\`\`\`\n`; }, list: (children, { depth }) => - Bun.wrapAnsi( - `${depth > 0 ? "\n" : ""}${children.trimEnd()}${depth === 0 ? "\n\n" : ""}`, - columns, - ), + `${depth > 0 ? "\n" : ""}${children.trimEnd()}${depth === 0 ? "\n\n" : ""}`, listItem: (children, { index, depth, ordered, start, checked }) => { const indent = " ".repeat(depth); let marker = ""; @@ -92,19 +91,21 @@ export async function renderMarkdown( } else { marker = "•"; } - return `${indent} ${marker} ${children}\n`; + return Bun.wrapAnsi(`${indent} ${marker} ${children}\n`, columns, { + trim: false, + }); }, hr: () => `${chalk.dim("─".repeat(columns))}\n\n`, table: (_children) => { - const table = new Table(); - table.header(header); - table.body(body); - table.border(); - table.maxColWidth(Math.floor(columns / header.length)); - const toRender = table.toString(); + const table = new Table() + .header(header) + .body(body) + .border() + .maxColWidth(Math.floor(columns / header.length) - 2) + .toString(); header = []; body = []; - return `${toRender}\n\n`; + return `${table}\n\n`; }, tr: (children) => { if (children) body.push(children.split(":tablesep:").slice(1));