nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Markdown tables with several columns render wider than the terminal, breaking their own borders

Open addyCooks opened this issue 2 months ago • 2 comments

Description

parseMarkdownTable clamps every column to a minimum of TABLE_COLUMN_MIN_WIDTH (10 columns) but never re-checks that the resulting total still fits the terminal. With enough columns, the proportional share per column falls under 10 and every column gets bumped back up to the floor, so the table's real rendered width can end up well past the terminal width cli-table3 was told to respect.

Parent: #907

Steps to Reproduce

  1. Ask Nanocoder to produce a markdown table with 6+ columns (e.g. "compare these 5 frontend frameworks across name, license, stars, language, last updated, maintainer, bundle size, downloads").
  2. View the response on a normal 80-column terminal.

Expected Behavior

The table's box-drawing borders stay aligned and contained within the terminal width, same as a narrow table does.

Actual Behavior

The table overflows the terminal width. Box-drawing border characters no longer line up under each other, rows wrap unpredictably, and at least one row fell back to rendering completely unparsed raw markdown (| solidjs | MIT | 32000 | ... |) instead of going through the table renderer at all.

Recording

Image

Root Cause

source/markdown-parser/table-parser.ts:66-77:

const borderWidth = numCols + 1; // vertical bars
const paddingWidth = numCols * 2; // 1 space on each side of each column
const availableWidth = terminalWidth - borderWidth - paddingWidth;

const totalContentWidth = contentWidths.reduce((a, b) => a + b, 0);
const colWidths = contentWidths.map(width =>
	Math.max(
		TABLE_COLUMN_MIN_WIDTH,
		Math.floor((width / totalContentWidth) * availableWidth),
	),
);

TABLE_COLUMN_MIN_WIDTH is 10 (source/constants.ts:88). Once enough columns each get floored to 10, sum(colWidths) + borderWidth + paddingWidth can exceed terminalWidth — e.g. 8 columns at 80 terminal columns: availableWidth = 80 - 9 - 16 = 55, but flooring every column to 10 makes the real width 8*10 + 9 + 16 = 105, 25 columns over budget. Nothing downstream rebalances or caps the total.

Suggested Fix

After computing colWidths, check whether their sum (+ border/padding overhead) exceeds availableWidth and, if so, shrink columns proportionally (or drop below the 10-column floor as a last resort) until the table fits or fall back to a non-table rendering (definition list style) when it structurally can't fit.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs on the latest main

addyCooks avatar Sep 20 '26 07:09 addyCooks

Hey @akramcodez, could you assign this to me ?

addyCooks avatar Sep 20 '26 07:09 addyCooks

Picking this up - a fix will follow shortly.

awhite0030 avatar Sep 21 '26 03:09 awhite0030