From f6bc2aecb7d2272e45362cdf22010cc9d268f0cf Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Fri, 20 Feb 2026 07:58:27 -0800 Subject: [PATCH] render markdown output for claude command results; add blank line before lists in markdown renderer --- src/cli.ts | 5 +++-- src/markdown.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index ec30cd3..bd3d402 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -9,6 +9,7 @@ import * as git from "./git.ts" import * as vm from "./vm.ts" import * as state from "./state.ts" import { spinner } from "./spinner.ts" +import { renderMarkdown } from "./markdown.ts" const pkg = await Bun.file(new URL("../package.json", import.meta.url)).json() @@ -178,7 +179,7 @@ program const output = await vm.claude(worktreeAbs, { prompt, print: opts.print }) if (output) { spin.stop() - process.stdout.write(output + "\n") + process.stdout.write(renderMarkdown(output) + "\n") } else { spin.succeed("Done") } @@ -310,7 +311,7 @@ program const output = await vm.claude(session.worktree, { prompt, print: opts.print }) if (output) { spin.stop() - process.stdout.write(output + "\n") + process.stdout.write(renderMarkdown(output) + "\n") } else { spin.succeed("Done") } diff --git a/src/markdown.ts b/src/markdown.ts index d53c4fb..a0a73f2 100644 --- a/src/markdown.ts +++ b/src/markdown.ts @@ -17,5 +17,14 @@ export function renderMarkdown(text: string): string { return `\x1b[38;5;147m${codeSpans[parseInt(i)]}\x1b[39m` }) + // Breathe: add blank line before list starts when preceded by non-empty text + const lines = result.split("\n") + for (let i = lines.length - 1; i > 0; i--) { + if (/^[\s]*[-*] /.test(lines[i]) && lines[i - 1].trim() !== "" && !/^[\s]*[-*] /.test(lines[i - 1])) { + lines.splice(i, 0, "") + } + } + result = lines.join("\n") + return result }