apache / apache/maka

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

Open
#5,083 2 comments 0 reactions 1 assignee Claimed by @yuzhiyang1 View on GitHub
enhancement
Dominant language
TypeScript
Stars
5.4k
Forks
502
Avg merge
1d 2h
Merged PRs (30d)
716

Description

### 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:

````markdown
```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._

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.