Documentation
¶
Overview ¶
Package highlight holds syntax highlighters for widget.TextArea (GtkSourceView's language definitions). Each styles spans with GtkSourceView's def: style ids, so one widget.TextScheme colors every language.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( Adwaita = widget.TextScheme{ "def:statement": {Color: render.RGB(0x1a, 0x5f, 0xb4)}, "def:net-address": {Color: render.RGB(0x77, 0x76, 0x7b)}, // contains filtered or unexported fields } AdwaitaDark = widget.TextScheme{ "def:statement": {Color: render.RGB(0x62, 0xa0, 0xea)}, "def:net-address": {Color: render.RGB(0x9a, 0x99, 0x96)}, // contains filtered or unexported fields } )
Adwaita and AdwaitaDark are the style schemes for the def: ids every language here emits, in the libadwaita palette for a light and a dark view (GtkSourceView's Adwaita schemes' roles). They leave the text and background to the theme; SchemeFor picks the one matching a theme.
Functions ¶
func ForFile ¶
func ForFile(path string) (widget.Highlighter, bool)
ForFile finds the highlighter whose globs match path's base name.
func Lookup ¶
func Lookup(name string) (widget.Highlighter, bool)
Lookup finds a language's highlighter by name or alias, ignoring case.
Types ¶
type Go ¶
type Go struct{}
Go highlights Go as GtkSourceView's go.lang does: line and block comments (//go: directives and // +build lines as def:preprocessor), keywords, predeclared types, constants (true and false as booleans) and builtin functions, interpreted strings with their escapes, raw strings, runes, and decimal, base-n, floating-point and imaginary numbers. Block comments and raw strings carry over through the line state.
type JSON ¶
type JSON struct{}
JSON highlights JSON as GtkSourceView's json.lang does: object keys (def:type, the TOML keys' style), strings with their escapes, numbers, true and false, null, and anything that is not JSON as def:error. JSON strings never span lines, so the state is always 0.
type Language ¶
type Language struct {
// Name is the language id, lower-case: "go", "json".
Name string
// Aliases are further names Lookup accepts.
Aliases []string
// Globs are filepath.Match patterns against a file's base name:
// "*.go", "Cargo.lock".
Globs []string
// Highlighter styles the language.
Highlighter widget.Highlighter
}
Language is a registered highlighter (a GtkSourceView language): its id, the other names it answers to (a Markdown fence's hint such as "golang" or "yml"), and the file-name patterns it claims.
type Markdown ¶
type Markdown struct{}
Markdown highlights CommonMark as GtkSourceView's markdown.lang does: ATX headings, thematic breaks, blockquote and list markers, inline code, strong and plain emphasis, links and autolinks, and backslash escapes. A fenced code block's lines go to the language its info string names (```go, ~~~yaml - any registered language or alias), carrying that language's own line state inside Markdown's; an unknown or missing hint styles the block preformatted.
type TOML ¶
type TOML struct{}
TOML highlights TOML as GtkSourceView's toml.lang does: comments, table headers (def:keyword), keys (def:type), strings with their escapes (def:special-char), booleans, integers (def:decimal), floats with inf and nan (def:floating-point), datetimes (def:constant), and anything else in a value as def:error. Multi-line strings, and arrays spanning lines, carry over through the line state.
type YAML ¶
type YAML struct{}
YAML highlights YAML as GtkSourceView's yaml.lang does: comments, document markers (def:preprocessor), mapping keys (def:type), anchors and aliases (def:identifier), tags (def:preprocessor), quoted strings with their escapes, block scalars (| and >, their lines def:string while indented past the key that opened them), and plain scalars typed as booleans, null, or numbers. Block scalars and quoted strings spanning lines carry over through the line state.