refactor: replace cli-table3 with @cliffy/table
This commit is contained in:
parent
8ff27c5de8
commit
9da57fe2fc
4 changed files with 19 additions and 21 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { Table } from "@cliffy/table";
|
||||
import chalk from "chalk";
|
||||
import CliTable3 from "cli-table3";
|
||||
import {
|
||||
type BundledLanguage,
|
||||
type BundledTheme,
|
||||
|
|
@ -32,7 +32,8 @@ export async function renderMarkdown(
|
|||
} catch {}
|
||||
}
|
||||
|
||||
let currentTable = new CliTable3();
|
||||
let header: string[] = [];
|
||||
let body: string[][] = [];
|
||||
|
||||
const rendered = Bun.markdown.render(md, {
|
||||
heading: (children, { level }) => {
|
||||
|
|
@ -88,17 +89,23 @@ export async function renderMarkdown(
|
|||
},
|
||||
hr: () => `${chalk.dim("─".repeat(columns))}\n\n`,
|
||||
table: (_children) => {
|
||||
const toRender = currentTable.toString();
|
||||
currentTable = new CliTable3();
|
||||
const table = new Table();
|
||||
table.header(header);
|
||||
table.body(body);
|
||||
table.border();
|
||||
table.maxColWidth(Math.floor(columns / header.length));
|
||||
const toRender = table.toString();
|
||||
header = [];
|
||||
body = [];
|
||||
return `${toRender}\n\n`;
|
||||
},
|
||||
tr: (children) => {
|
||||
if (children) currentTable.push(children.split(":tablesep:").slice(1));
|
||||
if (children) body.push(children.split(":tablesep:").slice(1));
|
||||
return "";
|
||||
},
|
||||
td: (children) => `:tablesep:${children}`,
|
||||
th: (children) => {
|
||||
currentTable.options.head.push(children);
|
||||
header.push(chalk.red(children));
|
||||
return "";
|
||||
},
|
||||
strong: (children) => chalk.bold(children),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue