Skip to main content

highlight

Function highlight 

Source
pub fn highlight(lang: &str, lines: &[&str]) -> Option<Vec<LineTokens>>
Expand description

Highlight the lines of one fenced code block written in lang.

One Vec per line, in order, each a list of byte ranges into that line with the token over them, ascending and non-overlapping. A byte no range covers carries no token — an identifier the grammar leaves as plain source.rust, the space between two words — and draws in the code colour. The lines are the block’s text split on \n, without terminators; the terminators are supplied here, since the grammars expect them.

None when lang names no grammar the set carries, which is the whole of the difference between “a language we can’t highlight” and “a block with nothing worth colouring”: a caller draws either in plain code colour, but only the second is a highlighted block.