fix(format): wrap markdown tables to terminal width - #1141
Open
Jorge-Polanco-Roque wants to merge 1 commit into
Open
fix(format): wrap markdown tables to terminal width#1141Jorge-Polanco-Roque wants to merge 1 commit into
Jorge-Polanco-Roque wants to merge 1 commit into
Conversation
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>
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #681.
Problem
gum formatrenders 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()passedglamour.WithWordWrap(0). glamour derives a table's per-cell width from the word-wrap width (BlockStack.Widthreturns 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/termwas already a direct dependency, so no new deps.Testing
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
blockedand 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.