Documentation
¶
Overview ¶
Package highlight colours source code for the web UI's diffs. It tokenises a whole file with chroma, so strings and comments that span lines colour correctly, and hands back each line's tokens tagged with one of a small fixed set of CSS classes (tk-k, tk-s, ...). It never produces HTML: the templates render the tokens and escape their text.
Index ¶
Constants ¶
const Budget = 150 * time.Millisecond
Budget bounds the time spent tokenising one file. Lines the lexer has not reached by then are shown plain.
const MaxSize = 256 << 10
MaxSize is the largest file that is highlighted; bigger files are shown plain to keep pages fast.
Variables ¶
This section is empty.
Functions ¶
func File ¶
File tokenises src, the contents of the file at name, and returns its tokens line by line: index 0 is line 1, and no token holds a newline. Tokenising stops once the first upto lines are done (all lines when upto is 0 or less), since a diff rarely shows the end of a file; lexing from the top still gets multi-line strings and comments right. The result can be shorter than the file; missing lines are meant to be shown plain. It returns nil when the file should be shown plain: no lexer knows the name, the file is larger than MaxSize, or it is binary or not UTF-8.
Types ¶
type Span ¶
Span is a piece of a rendered diff line: syntax class plus whether it is part of the changed region of an edited line.
func Overlay ¶
Overlay combines a line's syntax tokens with its word-level change marks (segs; nil when the line was not edited in place) into spans cut at both kinds of boundary. text is the line as the diff shows it; when the tokens do not spell it exactly, Overlay returns nil and the caller shows the line without syntax colours.