#20441: fix: preserve newlines for markdown table rendering in WebChat
size: XS
trusted-contributor
Cluster:
Markdown Rendering Improvements
Fixes #20410
## What changed
Preserve newlines before markdown parsing in Gateway WebChat so tables render as proper HTML tables instead of jammed inline text.
## AI-assisted contribution
This fix was generated by an AI agent (OpenClaw cron: gh-issues-fix)
## Testing
Validated with `pnpm build && pnpm check && pnpm test`
## Root cause
The fix addresses the root cause by not collapsing newlines before the markdown parser runs. Changed text normalization in `extractTextFromChatContent` to preserve newlines while collapsing other whitespace. The regex change from `/\\s+/g` to `/[^\\S\\n]+/g` allows markdown tables and lists to render properly in the Gateway WebChat UI by maintaining line breaks that the markdown parser (`marked`) needs to recognize table syntax.
---
**Greptile Summary**
Changed text normalization in `extractTextFromChatContent` to preserve newlines while collapsing other whitespace. The regex change from `/\\s+/g` to `/[^\\S\\n]+/g` allows markdown tables and lists to render properly in the Gateway WebChat UI by maintaining line breaks that the markdown parser (`marked`) needs to recognize table syntax.
**Confidence Score: 5/5**
- This PR is safe to merge with minimal risk
- The change is surgical (one regex modification), well-documented with inline comments referencing the issue, includes updated test coverage, and the regex pattern `/[^\\S\\n]+/g` is a standard technique for preserving newlines while normalizing other whitespace
- The PR passed the full test suite (`pnpm build && pnpm check && pnpm test`)
- Usage analysis shows that code paths with custom normalization functions bypass this change, limiting the impact scope to only those relying on the default behavior
- No files require special attention
<sub>Last reviewed commit: 5eecc8b</sub>
Most Similar PRs
#20419: fix(webchat): explicitly pass gfm and breaks options to marked.parse()
by Limitless2023 · 2026-02-18
78.2%
#2716: Fix #2678: markdown horizontal rules not rendering in web chat
by Ambar-13 · 2026-01-27
76.9%
#14940: fix(googlechat): convert Markdown formatting to Google Chat markup
by brandonwise · 2026-02-12
76.5%
#16733: fix(ui): avoid injected newlines when tool output is hidden
by jp117 · 2026-02-15
75.1%
#23073: fix(ui): strip reply directive tags from assistant messages in WebC...
by x4v13r1120 · 2026-02-22
75.0%
#15204: fix(ui): preserve angle-bracketed text in chat
by bufordtjustice2918 · 2026-02-13
74.3%
#23370: fix: strip [[reply_to_current]] tags from WebChat + validate invoke...
by alexmelges · 2026-02-22
74.3%
#23144: fix(ui): strip reply directive tags from assistant messages in WebC...
by echoVic · 2026-02-22
74.2%
#20231: fix: strip untrusted metadata blocks from chat history
by MisterGuy420 · 2026-02-18
74.1%
#14966: fix(webchat): preserve user message visibility after chat.send
by BenediktSchackenberg · 2026-02-12
74.0%