Skip to content

fix(format): wrap markdown tables to terminal width - #1141

Open
Jorge-Polanco-Roque wants to merge 1 commit into
charmbracelet:mainfrom
Jorge-Polanco-Roque:fix/format-markdown-table-width
Open

fix(format): wrap markdown tables to terminal width#1141
Jorge-Polanco-Roque wants to merge 1 commit into
charmbracelet:mainfrom
Jorge-Polanco-Roque:fix/format-markdown-table-width

Conversation

@Jorge-Polanco-Roque

Copy link
Copy Markdown

Fixes #681.

Problem

gum format renders a long cell in a markdown table on a single line, overflowing the terminal width and breaking the alignment of every row.

Root cause

markdown() passed glamour.WithWordWrap(0). glamour derives a table's per-cell width from the word-wrap width (BlockStack.Width returns 0 when word-wrap is 0), so the table is built with no width constraint and cells never wrap.

Approach

Wrap markdown to the terminal width, falling back to 80 (glamour's own default) when output isn't a terminal. code() keeps word-wrap 0 — code blocks must not be rewrapped. github.com/charmbracelet/x/term was already a direct dependency, so no new deps.

Testing

  • Added TestMarkdownTableWraps — verified it fails without the fix (line exceeds wrap width: 189 > 100).
  • go build ./... · go vet ./format/ · go test ./format/ green.

A note on direction

I saw this issue is labeled blocked and that @caarlos0 expects it resolved "once we start using lipgloss tables in glamour." This PR is offered as a small, self-contained stopgap — gum was explicitly disabling a wrapping feature glamour already supports — for users hitting broken tables today, not as a replacement for that upstream work. Happy to close it if you'd rather wait for the glamour/lipgloss route.

gum format passed WithWordWrap(0) to glamour, which disables wrapping.
glamour derives a table's cell width from the word-wrap width, so a zero
width means long table cells never wrap and the whole table overflows,
breaking the layout of every cell.

Wrap markdown to the terminal width (falling back to 80 when output is
not a terminal, matching glamour's own default) so long cells wrap inside
their column. Code blocks keep WithWordWrap(0) so code is never rewrapped.

Fixes charmbracelet#681

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Jorge-Polanco-Roque

Copy link
Copy Markdown
Author

Gentle ping on this one — it's been open about a week. It wraps markdown tables to the terminal width so wide tables don't overflow the viewport. Happy to rebase or adjust anything whenever a maintainer has a chance to look. Thanks for gum!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gum format: Long text in Markdown table breaks formatting for all cells

1 participant