fix: improve markdown list rendering and show messages for unsupported

This commit is contained in:
mitchell 2026-05-04 18:28:14 -04:00
parent c051f340a8
commit decfd2bde0

View file

@ -83,8 +83,8 @@ export async function renderMarkdown(
return `\`\`\`${chalk.blue(meta?.language ?? "")}\n${toRender}\`\`\`\n`;
},
list: (children, { depth }) => {
const trimmed = children.trimEnd();
return depth === 0 ? `${trimmed}\n\n` : `\n${trimmed}`;
const trimmed = children.replaceAll("\n\n", "\n");
return depth === 0 ? `${trimmed}\n` : `\n${trimmed}`;
},
listItem: (children, { index, depth, ordered, start, checked }) => {
let marker = "";
@ -100,7 +100,7 @@ export async function renderMarkdown(
const cols = columns - (depth + 1) * 2;
return Bun.wrapAnsi(`${marker} ${children}`, cols, { trim: false })
.split("\n")
.map((line) => ` ${line}`)
.map((line) => (line.length > 0 ? ` ${line}` : ""))
.join("\n")
.concat("\n");
},
@ -131,9 +131,9 @@ export async function renderMarkdown(
codespan: (children) => chalk.bgBlack.yellowBright(children),
link: (children, { href }) =>
chalk.blueBright.underline(terminalLink(children, href)),
image: () => "",
image: () => chalk.red("Images are unsupported (for now)\n"),
text: (children) => children,
html: () => "",
html: () => chalk.red("HTML is unsupported\n"),
});
return rendered.replace(/\n\n$/, "\n");