Skip to main content

Overview

The CodeRenderable component displays syntax-highlighted code using Tree-sitter for accurate parsing. It supports multiple languages, custom syntax themes, text selection, and streaming mode for incremental rendering.

Basic Usage

Props

string
default:"''"
Code content to display.
string
Language/filetype for syntax highlighting (e.g., "typescript", "python", "rust").
SyntaxStyle
required
Syntax styling configuration defining colors and attributes for language tokens.
TreeSitterClient
Tree-sitter client for syntax parsing. Uses default client if not provided.
boolean
default:"true"
Enable concealment of hidden syntax elements (used for markdown code blocks with fence markers).
boolean
default:"true"
Display unstyled text before syntax highlighting completes.
boolean
default:"false"
Enable streaming mode for incremental content updates.
(highlights: SimpleHighlight[], context: HighlightContext) => SimpleHighlight[] | undefined
Callback to modify or replace syntax highlights before rendering.
'none' | 'char' | 'word'
default:"'none'"
Text wrapping behavior.
boolean
default:"false"
Enable text selection with mouse or keyboard.
string | RGBA
Background color for selected text.
string | RGBA
Foreground color for selected text.

Supported Languages

CodeRenderable supports syntax highlighting for many languages through Tree-sitter:
  • JavaScript / TypeScript
  • Python
  • Rust
  • Go
  • C / C++
  • Java
  • Ruby
  • PHP
  • Markdown
  • JSON
  • YAML
  • And many more…

Examples

TypeScript with GitHub Dark Theme

Python Code

With Line Numbers

Selectable Code

Streaming Code Updates

Custom Highlight Callback

Word Wrapping

Switching Languages Dynamically

Common Syntax Style Groups

Different languages use different token names, but common ones include:
  • keyword, keyword.import, keyword.operator, keyword.coroutine
  • string, string.escape
  • comment, comment.line, comment.block
  • number, boolean
  • function, function.call, function.method, function.method.call
  • type, type.builtin
  • variable, variable.builtin, variable.parameter, variable.member
  • property
  • operator
  • punctuation, punctuation.bracket, punctuation.delimiter
  • constructor
  • constant, constant.builtin

Methods

getLineHighlights()

Get syntax highlights for a specific line.

Properties

content

Get or set the code content.

filetype

Get or set the language/filetype.

syntaxStyle

Get or set the syntax style.

conceal

Get or set conceal mode.

streaming

Get or set streaming mode.

drawUnstyledText

Get or set whether to draw unstyled text.

isHighlighting

Check if syntax highlighting is in progress.

Performance

  • Uses Tree-sitter for accurate, fast syntax parsing
  • Asynchronous highlighting to avoid blocking the UI
  • Caches highlights for unchanged content
  • Efficient incremental updates in streaming mode
  • Supports large code files with good performance
  • Text - Plain text display
  • Markdown - Markdown rendering (uses Code internally)
  • Diff - Side-by-side or unified diff views (uses Code internally)
  • LineNumberRenderable - Add line numbers to code