Skip to main content

Module highlight

Module highlight 

Source
Expand description

Lightweight, dependency-free syntax highlighting for inline previews.

The preview already caps what it reads (see crate::preview), so highlighting is a single linear pass over a small buffer. The scanner is deliberately simple — an approximation, not a full parser — and runs once when a document is loaded, caching the resulting spans with it. Rebuilds only replay the cached spans, so there is no per-frame cost.

Colors come from a process-wide Palette set at startup from the active theme (see crate::theme); the tree turns each TokenClass into a GtkTextTag.

Structs§

Palette
The colors used for each token class. Values are GTK color strings (#rrggbb), so they can be handed straight to a GtkTextTag.
Span
A highlighted range of the preview text, in character offsets (end is exclusive). Spans never overlap.

Enums§

Language
The language a preview is highlighted as.
TokenClass
A semantic token category. Each maps to one color in Palette.

Functions§

highlight
Highlight text as language. Character offsets in the returned spans index the same text; the text itself is never altered.
language_for
Pick the highlighting language from a file’s extension.
palette
The active syntax palette.
set_palette
Install the process-wide syntax palette. Only the first call wins.