highlight

package
v0.2.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 9 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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 Detect added in v0.2.14

func Detect(name, text string) (widget.Highlighter, bool)

Detect finds text's highlighter the way bat does: by the file's name (name may be "" for text from no file), then the interpreter its #! line names, then what its first line gives away ("package main", "<?xml"), then a vim or Emacs modeline in its first or last lines.

func ForFile

func ForFile(path string) (widget.Highlighter, bool)

ForFile finds the highlighter whose globs match path's base name.

func Languages

func Languages() []string

Languages lists the registered language names, sorted.

func Lookup

func Lookup(name string) (widget.Highlighter, bool)

Lookup finds a language's highlighter by name or alias, ignoring case.

func Register

func Register(lang Language)

Register adds lang, or replaces the language of the same name, so an application contributes its own languages (or overrides a built-in) without forking.

func SchemeFor

func SchemeFor(th *widget.Theme) widget.TextScheme

SchemeFor is the Adwaita scheme matching th's lightness.

Types

type CSS added in v0.2.14

type CSS struct{}

CSS highlights CSS as GtkSourceView's css.lang does: comments, at-rules (def:preprocessor), selectors' element names (def:keyword), classes and ids (def:type), property names (def:type), numbers with their units, colors (def:constant), strings, functions (def:builtin) and !important (def:keyword). A comment carries over through the line state, as does how deep in braces the line starts.

func (CSS) Highlight added in v0.2.14

func (CSS) Highlight(line []rune, state int) ([]widget.TextSpan, int)

Highlight implements widget.Highlighter.

type Diff added in v0.2.14

type Diff struct{}

Diff highlights unified and context diffs as GtkSourceView's diff.lang does: file headers (def:keyword), hunk locations (def:preprocessor), and added and removed lines (def:inserted, def:deleted). Every line stands alone.

func (Diff) Highlight added in v0.2.14

func (Diff) Highlight(line []rune, _ int) ([]widget.TextSpan, int)

Highlight implements widget.Highlighter.

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.

func (Go) Highlight

func (Go) Highlight(line []rune, state int) ([]widget.TextSpan, int)

Highlight implements widget.Highlighter.

type INI added in v0.2.14

type INI struct{}

INI highlights INI-style files - .ini, .conf, .desktop, systemd units, .gitconfig - as GtkSourceView's ini.lang does: comment lines (';' or '#'), [section] headers (def:keyword), keys (def:type), and values' booleans and numbers. Every line stands alone.

func (INI) Highlight added in v0.2.14

func (INI) Highlight(line []rune, _ int) ([]widget.TextSpan, int)

Highlight implements widget.Highlighter.

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.

func (JSON) Highlight

func (JSON) Highlight(line []rune, _ int) ([]widget.TextSpan, int)

Highlight implements widget.Highlighter.

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
	// Interpreters are the programs a script's #! line names to run
	// it: "python3", "bash".
	Interpreters []string
	// FirstLine matches a text's first line when it gives the language
	// away without a name or #! line: "package main", "<?xml", "diff --git".
	FirstLine *regexp.Regexp
	// 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.

func (Markdown) Highlight

func (Markdown) Highlight(line []rune, state int) ([]widget.TextSpan, int)

Highlight implements widget.Highlighter.

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.

func (TOML) Highlight

func (TOML) Highlight(line []rune, state int) ([]widget.TextSpan, int)

Highlight implements widget.Highlighter.

type Tags added in v0.2.14

type Tags struct{}

Tags highlights HTML and XML as GtkSourceView's html.lang and xml.lang do: tags and their names (def:keyword), attribute names (def:type) and quoted values (def:string), character references (def:special-char), comments, and declarations and processing instructions (def:preprocessor). A comment, a tag whose attributes run over lines, and a quoted value carry over through the line state.

func (Tags) Highlight added in v0.2.14

func (Tags) Highlight(line []rune, state int) ([]widget.TextSpan, int)

Highlight implements widget.Highlighter.

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.

func (YAML) Highlight

func (YAML) Highlight(line []rune, state int) ([]widget.TextSpan, int)

Highlight implements widget.Highlighter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL