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
|
# Finder (MacOS) folder config
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
# test markdown file
|
||||||
|
test.md
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ export default class Renderer {
|
||||||
|
|
||||||
const [columns] = pipe.getWindowSize();
|
const [columns] = pipe.getWindowSize();
|
||||||
const rendered = await renderMarkdown(str, columns);
|
const rendered = await renderMarkdown(str, columns);
|
||||||
pipe.write(rendered.replace(/\n\n$/, "\n"));
|
this.write(rendered);
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderStream(stream: AsyncIterableStream<TextStreamPart<ToolSet>>) {
|
async renderStream(stream: AsyncIterableStream<TextStreamPart<ToolSet>>) {
|
||||||
|
|
@ -157,6 +157,6 @@ export default class Renderer {
|
||||||
const output = (outputTokens ?? 0) / 1000;
|
const output = (outputTokens ?? 0) / 1000;
|
||||||
const time = (stop - start) / 1000;
|
const time = (stop - start) / 1000;
|
||||||
const template = `Context: ${context.toFixed(1)}k, Output: ${output.toFixed(1)}k, Time: ${time.toFixed(2)}s\n`;
|
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();
|
let currentTable = new CliTable3();
|
||||||
|
|
||||||
return Bun.markdown.render(md, {
|
const rendered = Bun.markdown.render(md, {
|
||||||
heading: (children, { level }) => {
|
heading: (children, { level }) => {
|
||||||
const colors = [
|
const colors = [
|
||||||
chalk.cyan.underline,
|
chalk.cyan.underline,
|
||||||
|
|
@ -69,7 +69,7 @@ export async function renderMarkdown(
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return `\`\`\`${chalk.blue(meta?.language)}\n${toRender}\n\`\`\`\n`;
|
return `\`\`\`${chalk.blue(meta?.language ?? "")}\n${toRender}\`\`\`\n`;
|
||||||
},
|
},
|
||||||
list: (children, { depth }) =>
|
list: (children, { depth }) =>
|
||||||
`${depth > 0 ? "\n" : ""}${children.trimEnd()}${depth === 0 ? "\n\n" : ""}`,
|
`${depth > 0 ? "\n" : ""}${children.trimEnd()}${depth === 0 ? "\n\n" : ""}`,
|
||||||
|
|
@ -77,14 +77,14 @@ export async function renderMarkdown(
|
||||||
const indent = " ".repeat(depth);
|
const indent = " ".repeat(depth);
|
||||||
let marker = "";
|
let marker = "";
|
||||||
if (checked !== undefined) {
|
if (checked !== undefined) {
|
||||||
marker = checked ? "[x]" : "[ ]";
|
marker = checked ? "[✓]" : "[ ]";
|
||||||
} else if (ordered) {
|
} else if (ordered) {
|
||||||
const n = (start ?? 1) + index;
|
const n = (start ?? 1) + index;
|
||||||
marker = `${n}.`;
|
marker = `${n}.`;
|
||||||
} else {
|
} else {
|
||||||
marker = "-";
|
marker = "•";
|
||||||
}
|
}
|
||||||
return `${indent}${marker} ${children}\n`;
|
return `${indent} ${marker} ${children}\n`;
|
||||||
},
|
},
|
||||||
hr: () => `${chalk.dim("─".repeat(columns))}\n\n`,
|
hr: () => `${chalk.dim("─".repeat(columns))}\n\n`,
|
||||||
table: (_children) => {
|
table: (_children) => {
|
||||||
|
|
@ -111,4 +111,6 @@ export async function renderMarkdown(
|
||||||
text: (children) => children,
|
text: (children) => children,
|
||||||
html: () => "",
|
html: () => "",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return rendered.replace(/\n\n$/, "\n");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue