Overview
TheCodeRenderable 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.coroutinestring,string.escapecomment,comment.line,comment.blocknumber,booleanfunction,function.call,function.method,function.method.calltype,type.builtinvariable,variable.builtin,variable.parameter,variable.memberpropertyoperatorpunctuation,punctuation.bracket,punctuation.delimiterconstructorconstant,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
Related Components
- 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