From efac14fd70cc16b0afb8175ad79d2182de2329c3 Mon Sep 17 00:00:00 2001 From: Bernie Birnbaum Date: Wed, 15 Jul 2026 11:38:58 -0400 Subject: [PATCH 1/3] elastic col width is at least the length of its name --- mdwn/table.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mdwn/table.go b/mdwn/table.go index 038d752..05614d3 100644 --- a/mdwn/table.go +++ b/mdwn/table.go @@ -188,9 +188,9 @@ func (t *Table) BuildMaxWidth(maxWidth int) (*Builder, error) { } budget := maxWidth - separatorOverhead - nonElasticSum - // Elastic column final width: floor at max(budget, 3, MinWidth). + // Elastic column final width: floor at max(budget, 3, MinWidth, len(Name)). elasticCol := t.cols[elasticIdx] - w := max(budget, 3, elasticCol.MinWidth) + w := max(budget, 3, elasticCol.MinWidth, len(elasticCol.Name)) // Apply MaxWidth ceiling if set. if elasticCol.MaxWidth > 0 && w > elasticCol.MaxWidth { w = elasticCol.MaxWidth From 8447f67cf5c853b1e173cafcb007580aa4daca18 Mon Sep 17 00:00:00 2001 From: Bernie Birnbaum Date: Wed, 15 Jul 2026 11:39:46 -0400 Subject: [PATCH 2/3] test elastic col name width --- mdwn/table_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mdwn/table_test.go b/mdwn/table_test.go index 4d75509..edfaf24 100644 --- a/mdwn/table_test.go +++ b/mdwn/table_test.go @@ -355,6 +355,23 @@ func TestTableBuildMaxWidth(t *testing.T) { assert.True(t, innerWidth >= 15) }) + t.Run("elastic column name length overrides budget", func(t *testing.T) { + cols := []Column{ + {Name: "Long"}, + {Name: "Even longer", Elastic: true}, + } + rows := [][]string{{"longvalue", "x"}} + got, err := buildMaxWidth(t, 10, cols, rows) + assert.NotError(t, err) + lines := strings.Split(strings.TrimRight(got, "\n"), "\n") + assert.True(t, len(lines) >= 3) + parts := strings.Split(lines[0], "|") + assert.True(t, len(parts) >= 3) + // inner cell width = len(parts[2]) - 2 (surrounding spaces) + innerWidth := utf8.RuneCountInString(parts[2]) - 2 + assert.True(t, innerWidth >= 10) + }) + t.Run("custom TruncMarker", func(t *testing.T) { // Custom marker "…" (single rune) on elastic column. cols := []Column{ From 9606d17ede1c8e7b8d241077b6f38ae3dba8d5d4 Mon Sep 17 00:00:00 2001 From: Bernie Birnbaum Date: Wed, 15 Jul 2026 13:53:00 -0400 Subject: [PATCH 3/3] gofmt --- mdwn/table_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mdwn/table_test.go b/mdwn/table_test.go index edfaf24..cd7bf01 100644 --- a/mdwn/table_test.go +++ b/mdwn/table_test.go @@ -355,7 +355,7 @@ func TestTableBuildMaxWidth(t *testing.T) { assert.True(t, innerWidth >= 15) }) - t.Run("elastic column name length overrides budget", func(t *testing.T) { + t.Run("elastic column name length overrides budget", func(t *testing.T) { cols := []Column{ {Name: "Long"}, {Name: "Even longer", Elastic: true}, @@ -371,7 +371,7 @@ func TestTableBuildMaxWidth(t *testing.T) { innerWidth := utf8.RuneCountInString(parts[2]) - 2 assert.True(t, innerWidth >= 10) }) - + t.Run("custom TruncMarker", func(t *testing.T) { // Custom marker "…" (single rune) on elastic column. cols := []Column{