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