fix: improve markdown rendering and codespan styling

This commit is contained in:
mitchell 2026-05-11 19:42:10 -04:00
parent efb44c4414
commit 7578e0ed2a

View file

@ -58,6 +58,7 @@ export async function renderMarkdown(
const lines = Bun.wrapAnsi(`\n${children.trim()}`, columns - 2, { const lines = Bun.wrapAnsi(`\n${children.trim()}`, columns - 2, {
trim: false, trim: false,
}) })
.replace(/\n([a-zA-Z-_]+)\n/g, "\n$1")
.concat("\n") .concat("\n")
.split("\n"); .split("\n");
const toRender = lines const toRender = lines
@ -83,7 +84,9 @@ 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.replace(/\n+/g, "\n"); const trimmed = children
.replace(/\n+/g, "\n")
.replace(/\n([a-zA-Z-_]+)\n/g, "\n$1");
return depth === 0 ? `${trimmed}\n` : `\n${trimmed}`; return depth === 0 ? `${trimmed}\n` : `\n${trimmed}`;
}, },
listItem: (children, { index, depth, ordered, start, checked }) => { listItem: (children, { index, depth, ordered, start, checked }) => {
@ -128,7 +131,7 @@ export async function renderMarkdown(
strong: (children) => chalk.bold(children), strong: (children) => chalk.bold(children),
emphasis: (children) => chalk.italic(children), emphasis: (children) => chalk.italic(children),
strikethrough: (children) => chalk.grey.strikethrough(children), strikethrough: (children) => chalk.grey.strikethrough(children),
codespan: (children) => chalk.bgBlack.yellowBright(children), codespan: (children) => chalk.bgYellow.black(children),
link: (children, { href }) => link: (children, { href }) =>
chalk.blueBright.underline(terminalLink(children, href)), chalk.blueBright.underline(terminalLink(children, href)),
image: () => chalk.red("Images are unsupported (for now)\n"), image: () => chalk.red("Images are unsupported (for now)\n"),