Skip to content

fix(ansi): render subsequent paragraphs in list items on new lines - #570

Open
troclaux wants to merge 1 commit into
charmbracelet:mainfrom
troclaux:fix/paragraphs-in-list-items
Open

fix(ansi): render subsequent paragraphs in list items on new lines#570
troclaux wants to merge 1 commit into
charmbracelet:mainfrom
troclaux:fix/paragraphs-in-list-items

Conversation

@troclaux

@troclaux troclaux commented Jun 3, 2026

Copy link
Copy Markdown

Summary

When a list item contains multiple paragraphs (loose list syntax), glamour concatenated them without any separator, producing broken output like:

• Here's the second list item.I need to add another paragraph below the second list item.

The KindParagraph handler skipped all paragraphs inside a KindListItem by returning Element{}. Only the first paragraph should be skipped (it's rendered inline as the list item text). Subsequent paragraphs need a newline before them.

Before:

  • This is the first list item.
  • Here's the second list item.I need to add another paragraph below the second list item.
  • And here's the third list item.

After:

  • This is the first list item.
  • Here's the second list item.
  I need to add another paragraph below the second list item.
  • And here's the third list item.

Changes

  • ansi/elements.go: check node.PreviousSibling() == nil in the KindParagraph / KindListItem branch; only skip the first paragraph, return Element{Entering: "\n"} for subsequent ones
  • testdata/issues/167.md: regression test input
  • ansi/testdata/TestRendererIssues/167.golden: expected golden output

Testing

go test ./... passes.

Fixes #167

When a list item contains multiple paragraphs (loose list), only the
first paragraph was skipped (rendered inline as list item text). All
subsequent paragraphs also returned an empty Element, causing them to
be concatenated directly after the first paragraph with no separator.

Fix by returning Element{Entering: "\n"} for non-first paragraphs
inside list items, so each continuation paragraph starts on a new line.

Fixes charmbracelet#167
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.

Paragraphs in lists are not rendered correctly

1 participant