style: markdown render improvements
This commit is contained in:
parent
d822ba2141
commit
430e99a972
3 changed files with 12 additions and 7 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -32,3 +32,6 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
|||
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
||||
|
||||
# test markdown file
|
||||
test.md
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ export default class Renderer {
|
|||
|
||||
const [columns] = pipe.getWindowSize();
|
||||
const rendered = await renderMarkdown(str, columns);
|
||||
pipe.write(rendered.replace(/\n\n$/, "\n"));
|
||||
this.write(rendered);
|
||||
}
|
||||
|
||||
async renderStream(stream: AsyncIterableStream<TextStreamPart<ToolSet>>) {
|
||||
|
|
@ -157,6 +157,6 @@ export default class Renderer {
|
|||
const output = (outputTokens ?? 0) / 1000;
|
||||
const time = (stop - start) / 1000;
|
||||
const template = `Context: ${context.toFixed(1)}k, Output: ${output.toFixed(1)}k, Time: ${time.toFixed(2)}s\n`;
|
||||
process.stderr.write(chalkStderr.dim(template));
|
||||
this.write(chalkStderr.dim(template), process.stderr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ export async function renderMarkdown(
|
|||
|
||||
let currentTable = new CliTable3();
|
||||
|
||||
return Bun.markdown.render(md, {
|
||||
const rendered = Bun.markdown.render(md, {
|
||||
heading: (children, { level }) => {
|
||||
const colors = [
|
||||
chalk.cyan.underline,
|
||||
|
|
@ -69,7 +69,7 @@ export async function renderMarkdown(
|
|||
} catch {}
|
||||
}
|
||||
|
||||
return `\`\`\`${chalk.blue(meta?.language)}\n${toRender}\n\`\`\`\n`;
|
||||
return `\`\`\`${chalk.blue(meta?.language ?? "")}\n${toRender}\`\`\`\n`;
|
||||
},
|
||||
list: (children, { depth }) =>
|
||||
`${depth > 0 ? "\n" : ""}${children.trimEnd()}${depth === 0 ? "\n\n" : ""}`,
|
||||
|
|
@ -77,12 +77,12 @@ export async function renderMarkdown(
|
|||
const indent = " ".repeat(depth);
|
||||
let marker = "";
|
||||
if (checked !== undefined) {
|
||||
marker = checked ? "[x]" : "[ ]";
|
||||
marker = checked ? "[✓]" : "[ ]";
|
||||
} else if (ordered) {
|
||||
const n = (start ?? 1) + index;
|
||||
marker = `${n}.`;
|
||||
} else {
|
||||
marker = "-";
|
||||
marker = "•";
|
||||
}
|
||||
return `${indent} ${marker} ${children}\n`;
|
||||
},
|
||||
|
|
@ -111,4 +111,6 @@ export async function renderMarkdown(
|
|||
text: (children) => children,
|
||||
html: () => "",
|
||||
});
|
||||
|
||||
return rendered.replace(/\n\n$/, "\n");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue