Skip to content

fix(markdown): harden code block fallback and info parsing#784

Open
ryanfreckleton wants to merge 3 commits intoanomalyco:mainfrom
ryanfreckleton:fix-markdown-codeblock-style-clean
Open

fix(markdown): harden code block fallback and info parsing#784
ryanfreckleton wants to merge 3 commits intoanomalyco:mainfrom
ryanfreckleton:fix-markdown-codeblock-style-clean

Conversation

@ryanfreckleton
Copy link

@ryanfreckleton ryanfreckleton commented Mar 6, 2026

Downstream: OpenCode

In OpenCode, fenced code blocks with unknown/unsupported languages are illegible on light terminal themes (for example, Solarized Light) because fallback plain-text rendering had no guaranteed base fg/bg.

Why here

  • The readability invariant belongs in CodeRenderable, not MarkdownRenderable, so all call sites (markdown and standalone) inherit safe defaults.
  • This matches how Rich, Glamour, and syntect/bat treat default style ownership.

Scope

  • CodeRenderable now derives baseline fg/bg/attributes from syntaxStyle["default"] when those props are omitted (and reapplies on syntaxStyle change without overriding explicit caller values).
  • MarkdownRenderable now normalizes fence language info as first token + lowercase + extToFiletype alias mapping (for example, BASH title=... -> shell, ToMl -> toml).

Validation

  • Manual: verified in the linked OpenCode worktree (~/src/opencode-opentui-test) that unknown-language fences remain readable on light themes.
  • Automated: bun test packages/core/src/renderables/Code.test.ts packages/core/src/renderables/__tests__/Markdown.test.ts

CodeRenderable now owns its own fg/bg fallback: it reads the `default`
style entry from its syntaxStyle theme and applies it as baseline colors
and attributes at construction and whenever syntaxStyle changes. This
means any code block automatically renders legibly on light themes
(e.g. Solarized Light) without requiring the parent container to
pass explicit fg/bg values.

Also hardens startHighlight against a temporarily-undefined syntaxStyle
during streaming, and normalises fenced code info strings in
MarkdownRenderable (first token, lowercase, alias map) so that
```BASH, ```TypeScript, etc. resolve to correct tree-sitter grammars.

Tests cover: unknown-language fallback colors, missing-syntaxStyle
robustness, case-insensitive alias/info-string normalisation.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 6, 2026

@opentui/core

npm i https://pkg.pr.new/@opentui/core@784

@opentui/react

npm i https://pkg.pr.new/@opentui/react@784

@opentui/solid

npm i https://pkg.pr.new/@opentui/solid@784

@opentui/core-darwin-arm64

npm i https://pkg.pr.new/@opentui/core-darwin-arm64@784

@opentui/core-darwin-x64

npm i https://pkg.pr.new/@opentui/core-darwin-x64@784

@opentui/core-linux-arm64

npm i https://pkg.pr.new/@opentui/core-linux-arm64@784

@opentui/core-linux-x64

npm i https://pkg.pr.new/@opentui/core-linux-x64@784

@opentui/core-win32-arm64

npm i https://pkg.pr.new/@opentui/core-win32-arm64@784

@opentui/core-win32-x64

npm i https://pkg.pr.new/@opentui/core-win32-x64@784

commit: 03583ca

@ryanfreckleton ryanfreckleton requested a review from msmps as a code owner March 7, 2026 19:04
@asaf-genie
Copy link

+1 for the alias fix (ts -> typescript)
GPT 5.4 loves using ts and it doesn't render properly in opencode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants