mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[GH-ISSUE #20302] issue: Newlines in Codeblocks Mysteriously Disappear #34675
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mherreshoff on GitHub (Dec 31, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/20302
Check Existing Issues
Installation Method
Docker
Open WebUI Version
v0.6.43
Ollama Version (if applicable)
No response
Operating System
Mac OS Tahoe 26.2
Browser (if applicable)
Firefox, 146.0.1 (aarch64)
Confirmation
README.md.Expected Behavior
When submitting a prompt containing a code block, the contents of the code block should appear verbatim in the chat log after pressing enter (and presumably should also be sent to the LLM verbatim). Its displayed line numbers should match those of the text file it was pasted from.
Actual Behavior
Blank lines mysteriously disappear from the code block. The line numbers displayed in the code block after hitting enter are also no longer correct.
Steps to Reproduce
Instructions
mainbranch should be checked out. Launch the client with./run-compose.sh. This gives us a fresh instance of OpenWebUI. When I ran this, themainbranch was ata7271532f8a38da46785afcaa7e65f9a45e7d753, where v0.6.43 was merged in.gpt-4-0613, though I doubt this matters.)The blank lines will vanish from the chat log.
Example Code Block For Testing
Logs & Screenshots
Screenshot from before pressing enter:
Screenshot after pressing enter
Note that if code were being preserved verbatim, there would be five lines, and line three should be blank.
Screenshot of console logs
(Nothing seems especially amiss here)
Container Logs
open_webui_container_logs.txt
Notes: Nothing seems to have gone wrong here either. I think the permissions error is unrelated, and was caused by me leaving one of my old browser windows open.
Additional Information
I searched through the existing issues and conversations as requested. The closest issues I found were:
@owui-terminator[bot] commented on GitHub (Dec 31, 2025):
🔍 Similar Issues Found
I found some existing issues that might be related to this one. Please check if any of these are duplicates or contain helpful solutions:
#19370 issue: new lines from CLIPBOARD problems on Windows
by daniporr • Nov 21, 2025 •
bug#20092 issue:
by VideoRyan • Dec 22, 2025 •
bug#20019 issue:
by j63440490 • Dec 17, 2025 •
bug#19861 issue:
by QuitHub • Dec 10, 2025 •
bug#19864 issue:
by Haervwe • Dec 10, 2025 •
bugShow 5 more related issues
#19777 issue:
by Yaute7 • Dec 05, 2025 •
bug#20046 issue:
by pierrelouisbescond • Dec 19, 2025 •
bug#19563 issue:
by naruto7g • Nov 28, 2025 •
bug#18922 issue: When code is present in the return output, the dialog box does not use code blocks.
by pureGavin • Nov 04, 2025 •
bug#16380 issue: Line breaks in tables are not rendered
by superjamie • Aug 08, 2025 •
bug💡 Tips:
This comment was generated automatically by a bot. Please react with a 👍 if this comment was helpful, or a 👎 if it was not.
@mherreshoff commented on GitHub (Dec 31, 2025):
Of the issues the
owui-terminatorbot surfaced, https://github.com/open-webui/open-webui/issues/19370 seems like the only related one. However, I doubt that fix will have any effect in this case since I tested this on a mac, and macs do not use CRLF newlines.@dannyl1u commented on GitHub (Jan 1, 2026):
Can confirm I can reproduce this issue on MacOS
@dannyl1u commented on GitHub (Jan 1, 2026):
Additional context: this occurs for regular text as well, not just code block
@silentoplayz commented on GitHub (Jan 1, 2026):
I am not able to reproduce this issue myself on Firefox or Chrome using the latest
devcommit on Ubuntu.@dannyl1u commented on GitHub (Jan 3, 2026):
The submission handler replaces double newlines (\n\n) and replaces them with single newlines (\n) for all content
a7271532f8/src/lib/components/chat/Chat.svelte (L2541)this results in a user message like:
gets sent to backend (e.g. OpenAI API) as
Checking if
settings.richTextInput === truehere would fix that, seems like this was the original behavior but was removed in153afd832c (diff-c867e0c9c90c94b02a2de567f2210ca9e600180d8fa3d6b121c7eb54da39a4edL2382)I believe we can still check if
settings.richTextInput === truehere for newline stripping while preserving the intention to deprecate textarea input.For code blocks, the Markdown renderer further collapses multiple newlines in the UI.
In Markdown.svelte,
breaks: trueis set,a7271532f8/src/lib/components/chat/Messages/Markdown.svelte (L40)however, per the docs, this only controls single newlines
https://marked.js.org/using_advanced?utm_source=chatgpt.com#:~:text=If%20true%2C%20add%20%3Cbr%3E%20on%20a%20single%20line%20break%20(copies%20GitHub%20behavior%20on%20comments%2C%20but%20not%20on%20rendered%20markdown%20files).%20Requires%20gfm%20be%20true.
@tjbck let me know if a PR is welcome/wanted here.
@silentoplayz can you reproduce the issue in https://github.com/open-webui/open-webui/discussions/6539 ?
@Classic298 commented on GitHub (Jan 3, 2026):
If you plan on doing a PR, good luck with that. I have tried many times to fix styling errors in the messageinput and richtextinput frontend files. Dozens of hours wasted in total to no avail. When you fix one thing, another breaks. Before submitting your changes as a PR, make sure you thoroughly test it locally in many different scenarios
@rgaricano commented on GitHub (Jan 3, 2026):
try changing this function:
6f1486ffd0/src/lib/components/common/RichTextInput.svelte (L418-L452)@Classic298 commented on GitHub (Jan 3, 2026):
I will not try changing anything anymore. I will not touch the messageinput or richtextinput anymore with a 10ft poll
If you want you can do it @rgaricano
Good luck fixing it without breaking something else.
I tried to fix this very issue and #20198 for the past days but couldn't find a solution that didn't break something else.
You need to keep up GitHub Markdown support, Rich text support with it enabled or disabled, if you fix #20198 then you will lose the newlines again even outside of a codeblock
It's horrendous to fix it
@silentoplayz commented on GitHub (Jan 3, 2026):
@dannyl1u Negative. I am not able to reproduce https://github.com/open-webui/open-webui/discussions/6539.
I can reproduce https://github.com/open-webui/open-webui/issues/20198 though.
@rgaricano commented on GitHub (Jan 3, 2026):
@Classic298
I was thinking more about @dannyl1u than you making the changes.
I don't know if I'm goint to have time to spend on that, my personal situation has changed radically and I have to make a decision between continuing to program or picking up a pick and shovel and dedicating myself to agricultural work in the countryside and to trees.
Also, since my system is very limited, it's difficult for me to work on several branches simultaneously (that's why I'm leaving reference notes instead of making a proposal and testing it).
In any case, I know it's problematic to work with codeblocks; they have the auto-rendering mechanism and frequent race collisions. I still have a pending proposal with the Mermaid and Vega diagrams; it's functional but has a small problem associated with this rendering configuration.
@tjbck commented on GitHub (Apr 17, 2026):
Addressed in dev.