fix: correct markdown rendering column widths and list formatting
This commit is contained in:
parent
ea5b3728a5
commit
22fc4c874f
1 changed files with 12 additions and 5 deletions
|
|
@ -53,9 +53,13 @@ export async function renderMarkdown(
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
paragraph: (children) =>
|
paragraph: (children) =>
|
||||||
Bun.wrapAnsi(`${children}\n\n`, columns - 2, { trim: false }),
|
Bun.wrapAnsi(`${children}\n\n`, columns, { trim: false }),
|
||||||
blockquote: (children) => {
|
blockquote: (children) => {
|
||||||
const lines = Bun.wrapAnsi(children, columns).split("\n");
|
const lines = Bun.wrapAnsi(`\n${children.trim()}`, columns - 2, {
|
||||||
|
trim: false,
|
||||||
|
})
|
||||||
|
.concat("\n")
|
||||||
|
.split("\n");
|
||||||
const toRender = lines
|
const toRender = lines
|
||||||
.map((line) => `${chalk.dim("> ")}${line}`)
|
.map((line) => `${chalk.dim("> ")}${line}`)
|
||||||
.join("\n")
|
.join("\n")
|
||||||
|
|
@ -78,8 +82,10 @@ 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 }) => {
|
||||||
`${depth > 0 ? "\n" : ""}${children.trimEnd()}${depth === 0 ? "\n\n" : ""}`,
|
const trimmed = children.trimEnd();
|
||||||
|
return depth === 0 ? `${trimmed}\n\n` : `\n${trimmed}`;
|
||||||
|
},
|
||||||
listItem: (children, { index, depth, ordered, start, checked }) => {
|
listItem: (children, { index, depth, ordered, start, checked }) => {
|
||||||
const indent = " ".repeat(depth);
|
const indent = " ".repeat(depth);
|
||||||
let marker = "";
|
let marker = "";
|
||||||
|
|
@ -91,6 +97,7 @@ export async function renderMarkdown(
|
||||||
} else {
|
} else {
|
||||||
marker = "•";
|
marker = "•";
|
||||||
}
|
}
|
||||||
|
|
||||||
return Bun.wrapAnsi(`${indent} ${marker} ${children}\n`, columns, {
|
return Bun.wrapAnsi(`${indent} ${marker} ${children}\n`, columns, {
|
||||||
trim: false,
|
trim: false,
|
||||||
});
|
});
|
||||||
|
|
@ -101,7 +108,7 @@ export async function renderMarkdown(
|
||||||
.header(header)
|
.header(header)
|
||||||
.body(body)
|
.body(body)
|
||||||
.border()
|
.border()
|
||||||
.maxColWidth(Math.floor(columns / header.length) - 2)
|
.maxColWidth(Math.floor(columns / header.length) - 3)
|
||||||
.toString();
|
.toString();
|
||||||
header = [];
|
header = [];
|
||||||
body = [];
|
body = [];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue