GeezerVison is showing github.com — feat(ui): render and improve code blocks in user messages by sandikodev · Pull Request #20942 · anomalyco/opencode
Conversation
sandikodev
commented
Apr 3, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #12791
Type of change
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
User messages display backtick syntax as raw text. This PR addresses that
with the following changes:
- Parse and render inline code (single backtick) and fenced code blocks
(triple backtick) in user message text
- Auto-collapse code blocks exceeding 8 lines with a show/hide toggle
- Add i18n keys for the toggle in en.ts and all 16 locale files
- Trim orphan leading newlines that appear after extracted code blocks
- Reduce excessive prose spacing in markdown.css (headings, hr, pre, table)
— this is opinionated, happy to revert if preferred
- Add syntax highlighting using the shared Shiki highlighter (same as
AI response code blocks), with async loading and plain text fallback
- Fallback to plain text when fenced code blocks are unbalanced (odd
number of triple backticks) — prevents malformed renders when users
paste content containing triple backticks, e.g. terminal output or
incident reports
How did you verify your code works?
Tested manually with inline code, short blocks, long blocks (700+ lines
with collapse), and multiple languages (Python, TypeScript, Bash, SQL, Rust).
Screenshots / recordings
1. Inline code rendering

2. Short code block rendered (no collapse)

3. Long code block — collapsed

4. Long code block — expanded

5. Syntax highlighting across multiple languages

Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Parse backtick syntax in user message text before rendering.
Triple backticks render via Markdown component (with syntax highlight),
single backticks render as inline <code> elements.
Closes #12791
- Replace Markdown component with native pre/code render to eliminate
excess spacing from prose styles
- Auto-collapse code blocks exceeding 8 lines with show/hide toggle
- Add styling for inline code and code block in user-message-text
Add ui.message.codeBlock.showMore and ui.message.codeBlock.showLess
keys to en.ts and use them in CodeBlock component instead of
hardcoded strings.
Add ui.message.codeBlock.showMore and ui.message.codeBlock.showLess
to all 16 non-English locale files.
Reduce margins on headings, paragraphs, hr, pre, and table elements
to improve visual density in AI responses. Values were previously
too large (2rem/2.5rem) causing excessive whitespace around code
blocks and section dividers.
When a fenced code block is extracted from user message text, the
closing ``` leaves trailing newlines that become orphan whitespace
in the next text segment. These are artifacts of the markdown syntax,
not intentional user spacing, so they are trimmed.
This is open for discussion — an alternative is to preserve them
and let the container handle spacing via CSS.
This was referenced Apr 3, 2026
Use getSharedHighlighter from @pierre/diffs (same as AI response code
blocks) to highlight fenced code blocks in user messages. Falls back
to plain pre/code while the highlighter loads asynchronously.
If the number of triple backticks in a user message is odd (unclosed
fence), skip parsing entirely and render as plain text. This prevents
malformed renders when users paste content that contains triple
backticks — a common case when sharing terminal output or reports.
…xt fallback
When a user message contains an odd number of triple backticks (unclosed
fence), append a closing fence instead of falling back to plain text.
This preserves code block formatting while preventing malformed renders.
Related to #20952
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|