Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mdwn/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions mdwn/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Loading