render markdown output for claude command results; add blank line before lists in markdown renderer

This commit is contained in:
Chris Wanstrath 2026-02-20 07:58:27 -08:00
parent 5beb35dbe2
commit f6bc2aecb7
2 changed files with 12 additions and 2 deletions

View File

@ -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")
}

View File

@ -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
}