GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(ui): render and improve code blocks in user messages by sandikodev · Pull Request #20942 · anomalyco/opencode

Conversation

@sandikodev

@sandikodev sandikodev commented Apr 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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:

  1. Parse and render inline code (single backtick) and fenced code blocks
    (triple backtick) in user message text
  2. Auto-collapse code blocks exceeding 8 lines with a show/hide toggle
  3. Add i18n keys for the toggle in en.ts and all 16 locale files
  4. Trim orphan leading newlines that appear after extracted code blocks
  5. Reduce excessive prose spacing in markdown.css (headings, hr, pre, table)
    — this is opinionated, happy to revert if preferred
  6. Add syntax highlighting using the shared Shiki highlighter (same as
    AI response code blocks), with async loading and plain text fallback
  7. 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
image

2. Short code block rendered (no collapse)
image

3. Long code block — collapsed
image

4. Long code block — expanded
image

5. Syntax highlighting across multiple languages
image

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.

All reactions
sandikodev added 6 commits April 4, 2026 03:05
@sandikodev
feat(ui): render inline code and code blocks in user messages
f0f82bc
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
@sandikodev
feat(ui): add collapse and fix spacing for user message code blocks
bf61394
- 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
@sandikodev
feat(ui): add i18n keys for user message code block toggle
f63f51c
Add ui.message.codeBlock.showMore and ui.message.codeBlock.showLess
keys to en.ts and use them in CodeBlock component instead of
hardcoded strings.
@sandikodev
feat(ui): add i18n translations for code block toggle in all locales
f162cd2
Add ui.message.codeBlock.showMore and ui.message.codeBlock.showLess
to all 16 non-English locale files.
@sandikodev
tweak(ui): reduce excessive spacing in markdown prose
72b53c6
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.
@sandikodev
fix(ui): trim orphan leading newlines after code blocks in user messages
975f175
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
[FEATURE]: Add copy button to code blocks in user messages #20943
Closed
feat(ui): add copy button to user message code blocks #20946
Closed
sandikodev added 2 commits April 4, 2026 07:18
@sandikodev
feat(ui): add syntax highlighting to user message code blocks
8099d2c
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.
@sandikodev
fix(ui): fallback to plain text when fenced code blocks are unbalanced
3629d2f
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.
@sandikodev sandikodev mentioned this pull request Apr 4, 2026
[FEATURE]: Validate and handle malformed fenced code blocks in user messages (follow-up to #20942) #20952
Closed
@sandikodev
fix(ui): auto-close unbalanced fenced code blocks instead of plain te…
c11610b
…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
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@sandikodev sandikodev closed this by deleting the head repository May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Render inline code and code blocks in user messages

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@sandikodev
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.