tuika-codeformatters 0.1.0

Tree-sitter syntax highlighting for tuika's CodeBlock and Markdown components — a ready-made Highlighter implementation.
Documentation

tuika-codeformatters

crates.io docs.rs

Tree-sitter syntax highlighting for tuika's CodeBlock and Markdown components.

tuika owns the presentation of code — framing, background, language label, wrapping — but deliberately depends on no grammar, so its dependency set stays small. This companion crate fills the gap: a ready-made tuika::Highlighter backed by tree-sitter grammars, mapping token classes onto the host Theme's code palette so highlighted code follows the theme.

use tuika::{CodeBlock, Theme};
use tuika_codeformatters::TreeSitterHighlighter;

let theme = Theme::default();
let hl = TreeSitterHighlighter::new();
let block = CodeBlock::new("rust", "fn main() {}").highlighter(&hl);
// `block` is a `View`; render it with `tuika::paint` or embed it in a `Flex`.
# let _ = (theme, block);

Example

A runnable, interactive gallery of highlighted snippets across languages (←/→ or Tab to switch, q to quit):

cargo run -p tuika-codeformatters --example languages

Supported languages

Rust, Python, TypeScript/JavaScript, TSX/JSX, Go, Java, Ruby, CSS, HTML, C#, PHP, Zig, Scala, and SQL (with common aliases: rs, py, ts, js, rb, c#, …). Unknown languages — or source that fails to parse — return None, and the caller renders the block as plain, theme-colored code.

Compatibility

ratatui and tuika are part of this crate's public interface, so pin the same minor versions in your own crate and Cargo will deduplicate them.

License

MIT