Skip to content

fix(chat): keep typed line breaks in user messages - #1015

Merged
agegr merged 2 commits into
mainfrom
claude/issue-680-user-line-breaks
Sep 30, 2026
Merged

agegr merged 2 commits into
mainfrom
claude/issue-680-user-line-breaks

Conversation

@agegr

@agegr agegr commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Fixes #680

Problem

User messages are rendered as Markdown. .markdown-user-message p { white-space: pre-wrap } keeps single line breaks inside paragraphs, but several cases still collapsed typed line breaks into spaces:

  • Lone \r line endings: Chrome renders \r as a space even under pre-wrap, which merges pasted text into one paragraph exactly as reported.
  • Soft breaks inside tight list items, e.g. an exam question 1. question\nA. option\nB. option, and setext headings. Their text is not inside a <p>, and adding pre-wrap to li turns the newlines between block children into blank lines.
  • Hard breaks (two trailing spaces or \) showed an extra blank line, because remark-rehype emits <br> plus a "\n" that pre-wrap renders again.

Changes

  • A small built-in remark plugin (no new dependency), used only for user messages through a new MarkdownBody keepLineBreaks prop, turns every line ending in text (\r\n, \r, \n) into a bare <br> via data.hName, and uses the same <br> for hard breaks. Code, inline code, math and raw HTML keep their text.
  • UserMessageView normalizes \r\n/\r so the plain-text paths (skill-command args and the raw view for oversized messages) also keep line breaks.
  • Assistant rendering is unchanged, and the pre-wrap rule stays so runs of spaces are still preserved. Rendering user messages as plain text remains an option if preferred.

Testing

  • New render tests in components/MarkdownBody.test.mjs and components/MessageView.test.mjs: LF/CRLF/CR, tight and nested lists, loose lists unchanged, setext heading, hard breaks, code and math untouched, assistant soft breaks unchanged, command args with \r. Six of them fail without the change.
  • tsc --noEmit and eslint on the changed files pass.
  • Checked in a real browser against a dev server with a session file holding the reported text with \r\n and with \r, plus an exam-style list: all render one line per typed line; before the fix the \r message merged into one paragraph and the list collapsed.

🤖 Generated with Claude Code

agegr and others added 2 commits September 30, 2026 21:36
User messages are rendered as Markdown, and
`.markdown-user-message p { white-space: pre-wrap }` keeps single line
breaks inside paragraphs. Several cases still collapsed typed line
breaks into spaces:

- Lone `\r` line endings: Chrome renders `\r` as a space even under
  pre-wrap, which merges pasted text into one paragraph exactly as
  reported.
- Soft breaks inside tight list items (an exam question
  `1. question\nA. option\nB. option`) and setext headings. Their text is
  not inside a `<p>`, and adding pre-wrap to `li` turns the newlines
  between block children into blank lines.
- Hard breaks (two trailing spaces or `\`) showed an extra blank line,
  because remark-rehype emits `<br>` plus a "\n" that pre-wrap renders
  again.

User messages now go through a small built-in remark plugin, selected by
a new `keepLineBreaks` prop on MarkdownBody, that turns every line ending
in text into a bare `<br>` and uses the same `<br>` for hard breaks.
Code, inline code, math and raw HTML keep their text. UserMessageView
also normalizes `\r\n`/`\r` so the plain-text paths (skill-command args,
the raw view of oversized messages) keep their breaks. Assistant
rendering is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…680)

A user message that mentions `<textarea>`, `<title>` or `<script>` without
backticks opens a raw-text element in rehype-raw, and the <br> the line-break
plugin placed after it ended that state: the lines were glued together or
the rest of the paragraph disappeared. A paragraph, heading or table cell
holding such a tag now renders as it did before, where the pre-wrap rule
still shows its newlines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr
agegr merged commit faeff03 into main Sep 30, 2026
2 checks passed
@agegr
agegr deleted the claude/issue-680-user-line-breaks branch October 1, 2026 13:28
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
解开 agegr#981 的 DirectoryPicker 冲突后,这一段(390e70f..f52fd84)实测 0 冲突:

- agegr#992 移动端输入框停在键盘上方并给打字更多空间
- agegr#997 限制每客户端 SSE 积压
- agegr#1001 可配置发送键(Enter / Ctrl+Enter)
- agegr#1006 从 pi 的 provider catalog 解析 discovery endpoint
- agegr#1017 空闲关闭被禁用时回收 Stop 无法解除的运行
- agegr#1016 Stop 结束输出被幸存进程持住的命令
- agegr#1015 保留用户消息里输入的换行
- agegr#1019 在 Safari / iOS 16.2 上可加载(新增 browserslist,无新依赖)
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
* fix(chat): keep typed line breaks in user messages (agegr#680)

User messages are rendered as Markdown, and
`.markdown-user-message p { white-space: pre-wrap }` keeps single line
breaks inside paragraphs. Several cases still collapsed typed line
breaks into spaces:

- Lone `\r` line endings: Chrome renders `\r` as a space even under
  pre-wrap, which merges pasted text into one paragraph exactly as
  reported.
- Soft breaks inside tight list items (an exam question
  `1. question\nA. option\nB. option`) and setext headings. Their text is
  not inside a `<p>`, and adding pre-wrap to `li` turns the newlines
  between block children into blank lines.
- Hard breaks (two trailing spaces or `\`) showed an extra blank line,
  because remark-rehype emits `<br>` plus a "\n" that pre-wrap renders
  again.

User messages now go through a small built-in remark plugin, selected by
a new `keepLineBreaks` prop on MarkdownBody, that turns every line ending
in text into a bare `<br>` and uses the same `<br>` for hard breaks.
Code, inline code, math and raw HTML keep their text. UserMessageView
also normalizes `\r\n`/`\r` so the plain-text paths (skill-command args,
the raw view of oversized messages) keep their breaks. Assistant
rendering is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(chat): leave blocks with raw-text tags to the default rendering (agegr#680)

A user message that mentions `<textarea>`, `<title>` or `<script>` without
backticks opens a raw-text element in rehype-raw, and the <br> the line-break
plugin placed after it ended that state: the lines were glued together or
the rest of the paragraph disappeared. A paragraph, heading or table cell
holding such a tag now renders as it did before, where the pre-wrap rule
still shows its newlines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
* fix(chat): keep typed line breaks in user messages (agegr#680)

User messages are rendered as Markdown, and
`.markdown-user-message p { white-space: pre-wrap }` keeps single line
breaks inside paragraphs. Several cases still collapsed typed line
breaks into spaces:

- Lone `\r` line endings: Chrome renders `\r` as a space even under
  pre-wrap, which merges pasted text into one paragraph exactly as
  reported.
- Soft breaks inside tight list items (an exam question
  `1. question\nA. option\nB. option`) and setext headings. Their text is
  not inside a `<p>`, and adding pre-wrap to `li` turns the newlines
  between block children into blank lines.
- Hard breaks (two trailing spaces or `\`) showed an extra blank line,
  because remark-rehype emits `<br>` plus a "\n" that pre-wrap renders
  again.

User messages now go through a small built-in remark plugin, selected by
a new `keepLineBreaks` prop on MarkdownBody, that turns every line ending
in text into a bare `<br>` and uses the same `<br>` for hard breaks.
Code, inline code, math and raw HTML keep their text. UserMessageView
also normalizes `\r\n`/`\r` so the plain-text paths (skill-command args,
the raw view of oversized messages) keep their breaks. Assistant
rendering is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(chat): leave blocks with raw-text tags to the default rendering (agegr#680)

A user message that mentions `<textarea>`, `<title>` or `<script>` without
backticks opens a raw-text element in rehype-raw, and the <br> the line-break
plugin placed after it ended that state: the lines were glued together or
the rest of the paragraph disappeared. A paragraph, heading or table cell
holding such a tag now renders as it did before, where the pre-wrap rule
still shows its newlines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Single line breaks in user messages are collapsed (Markdown soft breaks rendered as spaces)

1 participant