refactor: adjust markdown line wrapping

This commit is contained in:
mitchell 2026-05-03 23:11:02 -04:00
parent 5e733a4e14
commit b9610663a6

View file

@ -49,16 +49,18 @@ export async function renderMarkdown(
return Bun.wrapAnsi(
color.bold(`${"#".repeat(level)} ${children}\n\n`),
columns,
{ trim: false },
);
},
paragraph: (children) => Bun.wrapAnsi(`${children}\n\n`, columns),
paragraph: (children) =>
Bun.wrapAnsi(`${children}\n\n`, columns - 2, { trim: false }),
blockquote: (children) => {
const lines = children.split("\n");
const lines = Bun.wrapAnsi(children, columns).split("\n");
const toRender = lines
.map((line) => `${chalk.dim("> ")}${line}`)
.join("\n")
.replace(/\n$/, "\n\n");
return Bun.wrapAnsi(toRender, columns);
.concat("\n\n");
return toRender;
},
code: (children, meta) => {
let toRender = children;
@ -77,10 +79,7 @@ export async function renderMarkdown(
return `\`\`\`${chalk.blue(meta?.language ?? "")}\n${toRender}\`\`\`\n`;
},
list: (children, { depth }) =>
Bun.wrapAnsi(
`${depth > 0 ? "\n" : ""}${children.trimEnd()}${depth === 0 ? "\n\n" : ""}`,
columns,
),
`${depth > 0 ? "\n" : ""}${children.trimEnd()}${depth === 0 ? "\n\n" : ""}`,
listItem: (children, { index, depth, ordered, start, checked }) => {
const indent = " ".repeat(depth);
let marker = "";
@ -92,19 +91,21 @@ export async function renderMarkdown(
} else {
marker = "•";
}
return `${indent} ${marker} ${children}\n`;
return Bun.wrapAnsi(`${indent} ${marker} ${children}\n`, columns, {
trim: false,
});
},
hr: () => `${chalk.dim("─".repeat(columns))}\n\n`,
table: (_children) => {
const table = new Table();
table.header(header);
table.body(body);
table.border();
table.maxColWidth(Math.floor(columns / header.length));
const toRender = table.toString();
const table = new Table()
.header(header)
.body(body)
.border()
.maxColWidth(Math.floor(columns / header.length) - 2)
.toString();
header = [];
body = [];
return `${toRender}\n\n`;
return `${table}\n\n`;
},
tr: (children) => {
if (children) body.push(children.split(":tablesep:").slice(1));