Tree-sitter Highlighting

Build Status Build status Crates.io

Usage

Compile some languages into your app, and declare them:

rust extern "C" tree_sitter_html(); extern "C" tree_sitter_javascript();

Load some property sheets:

```rust use treesitterhighlight::loadpropertysheet;

let javascriptpropertysheet = loadpropertysheet( fs::readtostring("./tree-sitter-javascript/src/highlights.json").unwrap() ).unwrap();

let htmlpropertysheet = loadpropertysheet( fs::readtostring("./tree-sitter-html/src/highlights.json").unwrap() ).unwrap(); ```

Highlight some code:

```rust use treesitterhighlight::{highlight, HighlightEvent};

let highlights = highlight( b"const x = new Y();", unsafe { treesitterjavascript() }, &javascriptpropertysheet, &|_| None ).unwrap();

for event in highlights { match event { HighlightEvent::Source(s) { eprintln!("source: {:?}", s); }, HighlightEvent::ScopeStart(s) { eprintln!("scope started: {:?}", s); }, HighlightEvent::ScopeEnd(s) { eprintln!("scope ended: {:?}", s); }, } } ```

The last parameter to highlight is a language injection callback. This allows other languages to be retrieved when Tree-sitter detects an embedded document (for example, a piece of JavaScript code inside of a script tag within HTML).