Skip to main content

Crate syntax

Crate syntax 

Source
Expand description

Tree-sitter syntax classification for isolated code blocks.

highlight takes a source string and a fence tag and returns the highlighted spans as (byte range, kind) pairs, in document order. Everything outside those spans is unhighlighted text. There is no color and no rendering here — kinds map to colors through SyntaxPalette::color — and no injection machinery: the fence already names the grammar, so a block is one parse with one highlights query. Languages are a table (lang::LANGS, one row per feature); a grammar with no match returns None and the caller renders plain text.

A language the table does not carry is a Lang::new static of your own, highlighted through Lang::highlight — the same path the built-in rows take, so nothing about the query cache or the capture vocabulary has to be rebuilt to add one.

Re-exports§

pub use tree_sitter;
pub use tree_sitter_language;

Modules§

lang
The languages bezel can highlight: a row per grammar — the fence aliases it answers to, the tree-sitter grammar, and its highlights query. Each row is behind the feature of the same name.

Functions§

highlight
Highlight source as language (a fence tag — rs, py, tsx, …). None when the tag names no language.