highlight

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 8 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 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 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 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
	// 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 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