Skip to content

fix(ansi): collapse soft line breaks in list items by default - #580

Open
syf2211 wants to merge 1 commit into
charmbracelet:mainfrom
syf2211:fix/soft-line-breaks-in-lists
Open

fix(ansi): collapse soft line breaks in list items by default#580
syf2211 wants to merge 1 commit into
charmbracelet:mainfrom
syf2211:fix/soft-line-breaks-in-lists

Conversation

@syf2211

@syf2211 syf2211 commented Jun 25, 2026

Copy link
Copy Markdown

Summary

Soft line breaks in list item text were always rendered as hard newlines, even when PreserveNewLines is disabled.

Motivation

List items render through TextBlock nodes, not Paragraph, 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

  • In ansi/elements.go, render soft breaks as a space by default and as \n only when PreserveNewLines is enabled
  • Hard line breaks (\ or two trailing spaces) still render as newlines
  • Added TestListSoftLineBreaks covering soft vs hard breaks in bullet lists

Tests

  • go test ./... -count=1 — all pass

Notes

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

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
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.

2 participants