fix: improve markdown list rendering and show messages for unsupported
This commit is contained in:
parent
c051f340a8
commit
decfd2bde0
1 changed files with 5 additions and 5 deletions
|
|
@ -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");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue