highlight

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

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 colours one line of a file by its kind, for display.

It is line-based on purpose: a diff shows lines, not files, and a line of JSON, INI, TOML, YAML, a properties file, an ssh_config or a netrc can be classified on its own well enough to read. It never decides anything about the content - a wrong colour is the worst it can do - and it never builds HTML: it returns tokens, and the caller escapes them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(lang Lang, text string) (checked bool, problem string)

Check validates a whole file for the languages that can be checked without a parser authama does not have: JSON today. It reports whether a check ran, and the problem if one did and failed, with its line and column.

Types

type Kind

type Kind string

Kind is a token's class; the CSS names it tok-<kind>.

const (
	Text    Kind = ""
	Key     Kind = "key"
	String  Kind = "str"
	Number  Kind = "num"
	Literal Kind = "lit" // true, false, null, yes, no
	Comment Kind = "com"
	Punct   Kind = "pun"
	Section Kind = "sec" // [section], Host, Match
)

type Lang

type Lang string

Lang is a file kind the highlighter knows.

const (
	Plain      Lang = ""
	JSON       Lang = "json"
	INI        Lang = "ini" // .pypirc, .gitconfig, git credential files
	TOML       Lang = "toml"
	YAML       Lang = "yaml"
	Properties Lang = "properties"
	SSHConfig  Lang = "ssh"
	Netrc      Lang = "netrc"
	Shell      Lang = "sh"
)

func For

func For(path string) Lang

For names the language of a file from its name.

type Token

type Token struct {
	Kind Kind
	Text string
}

Token is a run of text and its kind.

func Line

func Line(lang Lang, s string) []Token

Line splits one line into tokens. Concatenating their Text gives the line back exactly.

Jump to

Keyboard shortcuts

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