Fix markdown rendering by parsing content as blocks instead of line-by-line #8369
+100
−24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The chat interface parsed markdown line-by-line, breaking multi-line constructs: code blocks rendered as text with visible backticks, each list item created a separate
<ul>, tables displayed as raw markdown, and blockquotes fragmented across lines.Changes
Markdown Parsing
Changed from line-by-line to block parsing in 5 locations:
Files:
core/http/views/chat.html- 3 instances (tool_call/tool_result fallback, thinking/reasoning, new messages)core/http/static/chat.js- 2 instances (thinking/reasoning, new messages)CSS Additions
Added markdown-specific styles to
core/http/static/general.css:max-width: calc(100vw - 3rem)for code blocksContainer Fix
Replaced invalid
overflow-wrap-anywhereTailwind class with proper CSS:Visual Comparison
Left shows broken rendering (line-by-line), right shows fixed rendering (block parsing).
Original prompt
Fix Chat Interface Markdown Rendering and Mobile Responsiveness
Problem Description
The web user interface does not parse model responses correctly. Markdown content (especially code blocks, lists, tables) appears messed up and not properly rendered. Additionally, long output from the LLM can go out of the window horizontally, requiring scrolling. The interface is also not well optimized for mobile devices.
Related Issue: #8259
Root Causes Identified
Issue 1: Incorrect Markdown Parsing (CRITICAL)
Location:
core/http/views/chat.html(lines ~333-337, ~369-373) andcore/http/static/chat.js(lines ~2459-2462, ~2478-2481)The code parses markdown line-by-line instead of as a complete block:
This breaks multi-line markdown constructs such as:
<ul>or<ol>)Fix: Parse the entire content as a single block:
Issue 2: Missing CSS for Markdown Content
Location:
core/http/static/general.css,core/http/static/components.cssThere are no styles for markdown-rendered content inside chat messages. Missing:
pre,code) with horizontal scrollingIssue 3: Invalid/Missing Overflow Classes
Location:
core/http/views/chat.html(line ~1334)overflow-wrap-anywhereis not a valid Tailwind class. Should use proper CSS for word wrapping and overflow handling.Issue 4: Container Width Issues
The
max-w-3xlfixed width on the messages container causes issues when content (like code blocks) exceeds this width, creating horizontal scrolling for the entire page.Issue 5: Mobile Responsiveness
w-56(224px) width that doesn't adaptmax-width: 100vwconstraints on mobileRequired Changes
1. Fix Markdown Parsing in
chat.htmlIn the Alpine store's
add()function, replace all instances of line-by-line parsing:Before:
After:
This needs to be done in multiple places in the
add()function (for thinking/reasoning, merged messages, and new messages).2. Fix Markdown Parsing in
chat.jsSame fix needs to be applied in the fallback Alpine store initialization in
chat.js.3. Add CSS for Markdown Content in
general.cssAdd comprehensive styles for markdown elements in chat messages: