Skip to content

preserve line breaks and indentation in welcome messages#1718

Merged
dgageot merged 3 commits intodocker:mainfrom
maxcleme:co-preserve-line-breaks
Feb 13, 2026
Merged

preserve line breaks and indentation in welcome messages#1718
dgageot merged 3 commits intodocker:mainfrom
maxcleme:co-preserve-line-breaks

Conversation

@maxcleme
Copy link
Member

@maxcleme maxcleme commented Feb 13, 2026

    welcome_message: |
      weuhweru
        wuiehweru
          weiruhwieurh

is rendered as:

Screenshot 2026-02-13 at 13 24 19

TBH I wonder if it should be considered markdown implicitly as of today. It makes pretty hard to create banner and such. Maybe it should be printed "as-is" instead? Wdyt?

Signed-off-by: maxcleme <maxime.clement@docker.com>
Signed-off-by: maxcleme <maxime.clement@docker.com>
Signed-off-by: maxcleme <maxime.clement@docker.com>
@maxcleme maxcleme marked this pull request as ready for review February 13, 2026 12:26
@maxcleme maxcleme requested a review from a team as a code owner February 13, 2026 12:26
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Found 1 issue in the changed code that should be addressed.

The PR implements indentation and line break preservation well with comprehensive tests. However, there's an inconsistency in the error handling path where the processed content is not used on fallback.

rendered, err := markdown.NewRenderer(width - messageStyle.GetHorizontalFrameSize()).Render(msg.Content)
// Convert explicit newlines to markdown hard line breaks (two trailing spaces)
// This preserves line breaks from YAML multiline syntax (|) while still
// allowing markdown formatting like **bold** and *italic*
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error fallback uses original content instead of processed content

The preserveLineBreaks() function is called on line 151 and stores the result in the content variable (leading spaces converted to non-breaking spaces). However, when markdown rendering fails, line 153 falls back to msg.Content instead of content, which loses the indentation processing.

Suggested change
// allowing markdown formatting like **bold** and *italic*
rendered = content

This ensures consistent behavior where indentation is preserved regardless of whether markdown rendering succeeds or fails. While rendering errors should be rare, they can occur and would currently cause unexpected loss of indentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line numbers of this suggestion are off a bit. I'll take a look at fixing it today.

@dgageot dgageot merged commit 206db7e into docker:main Feb 13, 2026
14 checks passed
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.

3 participants