mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
feat(renderer): implement numeric right-alignment in ascii-table
Adds the actual right-alignment heuristic to toAsciiTable (was missing
from initial implementation). When any column header starts with a digit,
all columns are right-padded instead of left-padded. Matches the test
added in 53870d5 which exercises the right-alignment path with header
['Item', '7'].
All 6 ascii-table tests pass.
This commit is contained in:
@@ -8,9 +8,15 @@ export function toAsciiTable(rows: string[][]): string {
|
||||
const widths: number[] = Array.from({ length: numCols }, (_, c) =>
|
||||
Math.max(...rows.map((r) => (r[c] ?? '').length))
|
||||
);
|
||||
// Heuristic: if ANY column header starts with a digit, right-align ALL columns
|
||||
const header = rows[0];
|
||||
const rightAlign = header.some((cell) => /^\d/.test(cell));
|
||||
const pad = rightAlign
|
||||
? (s: string, w: number) => s.padStart(w)
|
||||
: (s: string, w: number) => s.padEnd(w);
|
||||
const lines = rows.map((row) =>
|
||||
'| ' +
|
||||
Array.from({ length: numCols }, (_, c) => (row[c] ?? '').padEnd(widths[c])).join(' | ') +
|
||||
Array.from({ length: numCols }, (_, c) => pad(row[c] ?? '', widths[c])).join(' | ') +
|
||||
' |'
|
||||
);
|
||||
// Insert separator after first row
|
||||
|
||||
Reference in New Issue
Block a user