Skip to content

feat(tui): add syntax highlighting to Markdown code blocks #5083

Description

@me2seeks

Problem

Fenced code blocks in the TUI are recognized and rendered, but their contents have no syntax highlighting. This makes types, literals and keywords harder to distinguish when reading code in an assistant response.

Verified in local source at 9cb5cc93c03f8d07550e739164d5e33168892563: packages/cli/src/pi-transcript.ts uses pi-tui's Markdown component; markdownTheme in packages/cli/src/pi-transcript-format.ts sets codeBlock: (text) => text and does not configure the available highlightCode(code, lang) hook. This is a presentation enhancement, not a claim that fenced-code parsing is broken.

Representative input:

```typescript
todos: { content: string, status: "pending" | "in_progress" | "completed", activeForm?: string }[]
```

Desired outcome

Enable syntax highlighting by default for supported code-block languages in both the live conversation and detailed transcript reader, using consistent terminal styles.

  • Integrate highlighting through the existing Markdown theme hook, with a documented supported-language/alias policy.
  • Unknown or missing language tags and highlighting failures fall back to readable plain code without interrupting rendering.
  • Preserve code text, whitespace and logical line breaks; highlighting adds presentation only and does not modify stored message content.
  • Respect existing terminal color capabilities and no-color behavior; code remains readable without color.
  • Verify closed and streaming/unclosed fences, Chinese text, long lines, narrow terminals and resizing. Streaming highlighting must not introduce disruptive reflow or noticeably block input.
  • Provide same-content before/after terminal evidence for the live conversation and detailed reader, plus focused validation of fallback and content preservation.

Scope is code-block syntax highlighting. Fence appearance, wrapping redesign, Ctrl+O semantics, a raw-Markdown mode, clipboard features and general tool-card redesign are outside this issue. Related reading/navigation work remains in #5016; this issue does not imply those capabilities need to be rebuilt.

Alternatives or workarounds

Read the current plain code blocks or inspect code in an external editor. Replacing the Markdown renderer is not required; the existing pi-tui hook provides an integration point. Select the highlighting implementation during development based on terminal compatibility, dependency cost and streaming behavior.

AI assistance disclosure: Drafted with Codex at the author's direction.

Activity

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions