Skip to main content

Module highlight

Module highlight 

Source
Expand description

From a highlighter’s names to the code colour roles.

A highlighter, tree-sitter or anything that speaks its vocabulary, names each token with a dotted capture name such as keyword.return or variable.parameter. The Renderer does not know any language and never hears these names: they are turned into colour roles here, on the Host side, and the roles travel as the Paint of a span the way any other coloured run does. Markdown is handled the same way, for the same reason.

The names are matched from the most specific prefix down, so string.escape is an escape while string.special is still a string, and a name nothing here recognises gives None. A token without a role is left in the body ink rather than painted a guess.

Functions§

highlight_span
A span painting length bytes from start in the role a highlight name maps to, or None where the name has no role and the run is left in the body ink.
role_for_highlight
The colour role a highlight name is painted with, or None to leave it in the body ink.