fix: blockquote and list whitespace handling in markdown rendering

This commit is contained in:
mitchell 2026-05-12 16:34:13 -04:00
parent af52e89928
commit 7367cfdfe3

View file

@ -64,13 +64,14 @@ export async function renderMarkdown(
const lines = Bun.wrapAnsi(`\n${children.trim()}`, columns - 2, {
trim: false,
})
.replace(/\n(\s?[a-zA-Z_-]+\s?)\n/g, "\n$1")
.replace(/\n+/g, "\n")
.concat("\n")
.split("\n");
const toRender = lines
.map((line) => `${chalk.dim("> ")}${line}`)
.map((line) => `> ${line}`)
.join("\n")
.replace(/(\n> +\S+) *\n> */g, "$1 ")
.replaceAll(">", chalk.dim(">"))
.concat("\n\n");
return toRender;
},
@ -91,9 +92,7 @@ export async function renderMarkdown(
return `\`\`\`${chalk.blue(meta?.language ?? "")}\n${toRender}\`\`\`\n`;
},
list: (children, { depth }) => {
const trimmed = children
.replace(/\n+/g, "\n")
.replace(/\n(\s?[a-zA-Z_-]+\s?)\n/g, "\n$1");
const trimmed = children.replace(/\n+/g, "\n");
return depth === 0 ? `${trimmed}\n` : `\n${trimmed}`;
},
listItem: (children, { index, depth, ordered, start, checked }) => {
@ -112,6 +111,7 @@ export async function renderMarkdown(
.split("\n")
.map((line) => (line.length > 0 ? ` ${line}` : ""))
.join("\n")
.replace(/(\n +\S+) *\n */g, "$1 ")
.concat("\n");
},
hr: () => `${chalk.dim("─".repeat(columns))}\n\n`,