fix(cli): preserve Markdown table edge spaces (#7506)

Fixes morluto/rea#7432

Signed-off-by: pqminh27 <minh8a1hb@gmail.com>
This commit is contained in:
PM authored and GitHub committed 2026-10-28 05:16:28 +08:00
1 parent 6efb384261
commit 423d190026
2 files changed
+120 -3

No files matched your search

+7 -3
View File
@@ -84,11 +84,15 @@ const renderTable = (
rows: readonly string[][],
): string => {
if (headers.length === 0) return "";
const escapedHeaders = headers.map(escapeTableCell);
const encodeTableCell = (value: string): string =>
escapeTableCell(value).replace(/^ +| +$/g, (spaces) =>
"&#32;".repeat(spaces.length),
);
const escapedHeaders = headers.map(encodeTableCell);
const widths = escapedHeaders.map((header) => header.length);
for (const row of rows) {
for (let index = 0; index < escapedHeaders.length; index += 1) {
const width = escapeTableCell(row[index] ?? "").length;
const width = encodeTableCell(row[index] ?? "").length;
if (width > widths[index]!) widths[index] = width;
}
}
@@ -102,7 +106,7 @@ const renderTable = (
for (const row of rows) {
lines.push(
`| ${escapedHeaders
.map((_, index) => pad(escapeTableCell(row[index] ?? ""), index))
.map((_, index) => pad(encodeTableCell(row[index] ?? ""), index))
.join(" | ")} |`,
);
}