Skip to main content

Highlighter

Trait Highlighter 

Source
pub trait Highlighter {
    // Required methods
    fn supports(&self, lang: &str) -> bool;
    fn highlight_line(
        &self,
        lang: &str,
        line: &str,
        state: State,
        out: &mut Vec<Span>,
    ) -> State;

    // Provided method
    fn highlight(&self, lang: &str, text: &str, out: &mut Vec<Span>) { ... }
}
Expand description

A syntax highlighting engine. Builtin is the lexers of this crate; a bigger engine (a grammar-based one, say) can implement this and be used by the same views.

Required Methods§

Source

fn supports(&self, lang: &str) -> bool

Whether this engine highlights lang (a name, alias or extension).

Source

fn highlight_line( &self, lang: &str, line: &str, state: State, out: &mut Vec<Span>, ) -> State

Highlights one line starting in state, appending line-relative spans to out, and returns the state the next line starts in. Spans must follow the rules of Span; an engine without line states may return state unchanged.

Provided Methods§

Source

fn highlight(&self, lang: &str, text: &str, out: &mut Vec<Span>)

Highlights a whole text, appending spans relative to text to out.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§