fix(ansi): collapse soft line breaks in list items by default - #580
Open
syf2211 wants to merge 1 commit into
Open
fix(ansi): collapse soft line breaks in list items by default#580syf2211 wants to merge 1 commit into
syf2211 wants to merge 1 commit into
Conversation
Soft line breaks were always rendered as newlines in text nodes, which bypassed paragraph-level newline collapsing for list item TextBlocks. Only preserve soft breaks when PreserveNewLines is enabled; hard breaks still render as line breaks. Fixes charmbracelet/glow#858
syf2211
force-pushed
the
fix/soft-line-breaks-in-lists
branch
from
June 25, 2026 22:46
cf6fc66 to
fa47020
Compare
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.
Summary
Soft line breaks in list item text were always rendered as hard newlines, even when
PreserveNewLinesis disabled.Motivation
List items render through
TextBlocknodes, notParagraph, so paragraph-level newline collapsing never applied. This caused glow #858: soft breaks inside list items were preserved while body text correctly collapsed them.Changes
ansi/elements.go, render soft breaks as a space by default and as\nonly whenPreserveNewLinesis enabled\or two trailing spaces) still render as newlinesTestListSoftLineBreakscovering soft vs hard breaks in bullet listsTests
go test ./... -count=1— all passNotes
Glow currently depends on glamour v0.10.0; this fix lands in glamour v2 main. A follow-up glow PR can bump the dependency once released.
Related to charmbracelet/glow#858