mirror of
https://github.com/morluto/rea.git
synced 2026-11-12 09:52:27 +00:00
fix(cli): preserve Markdown table edge spaces (#7506)
Fixes morluto/rea#7432 Signed-off-by: pqminh27 <minh8a1hb@gmail.com>
This commit is contained in:
2 files changed
+120
-3
No files matched your search
@@ -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) =>
|
||||
" ".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(" | ")} |`,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user