syntax

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 5 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 syntax is what code highlighting in base shares: the kinds of tokens, chroma's token types mapped onto them and NSH's palette, Allsum's, in light and dark.

Index

Constants

This section is empty.

Variables

View Source
var (
	Light = [Kinds]core.Style{
		Comment: {Color: core.RGB(0x6e7781), FontStyle: core.FontStyleItalic},
		Keyword: color(0x8250df), String: color(0x116329), Number: color(0x953800), Title: color(0x0550ae),
		Attr: color(0x7d4e00), Built: color(0x0a7285), Deletion: color(0xcf222e),
		Bold: {FontWeight: core.FontWeightBold}, Italic: {FontStyle: core.FontStyleItalic},
	}
	Dark = [Kinds]core.Style{
		Comment: {Color: core.RGB(0x7d7a72), FontStyle: core.FontStyleItalic},
		Keyword: color(0xc4a7ff), String: color(0x9fd68a), Number: color(0xf5b27a), Title: color(0x82b8ff),
		Attr: color(0xf0c674), Built: color(0x6fd3d8), Deletion: color(0xf87171),
		Bold: {FontWeight: core.FontWeightBold}, Italic: {FontStyle: core.FontStyleItalic},
	}
)

Functions

func HighlightLines

func HighlightLines(h Highlighter, lines []string, from, to int) [][]Tok

HighlightLines runs h over lines from to to and returns their runs as Toks, sorted and clipped to each line.

func LexLines

func LexLines(lexer chroma.Lexer, lines []string) [][]Tok

LexLines lexes lines with lexer from its root state: the runs of each line that are not plain. It takes its time; run it off the engine goroutine.

func Lexer

func Lexer(name string) chroma.Lexer

Lexer is chroma's lexer for a language's name or a file's path, coalesced; nil for none.

Types

type Highlighter

type Highlighter interface {
	// Highlight returns the tokens of lines from to to (exclusive) of
	// lines, a snapshot of the whole text without line breaks: one slice
	// per line, its tokens in bytes of the line.
	Highlight(lines []string, from, to int) [][]Token
}

Highlighter is an app's highlighting of a language, in place of chroma's, for the Editor and the DiffView alike. It runs off the engine goroutine.

type Kind

type Kind uint8

Kind is a kind of token in code, as NSH's palette names them.

const (
	Plain Kind = iota
	Comment
	Keyword
	String
	Number
	Title
	Attr
	Built
	Deletion
	Bold
	Italic
	Kinds
)

The kinds; Kinds counts them.

func KindNamed

func KindNamed(name string) Kind

KindNamed is the Kind a name gives, Plain for none: a decoration's or an app's token's.

func KindOf

func KindOf(t chroma.TokenType) Kind

KindOf maps chroma's token types to the palette's Kinds.

type Tok

type Tok struct {
	Start, End int
	Kind       Kind
}

Tok is a run of a line of one kind, in bytes.

type Token

type Token struct {
	Start, End int
	Kind       string
}

Token is a run of a line an app's highlighter colors: from byte Start to End, as the kind Kind names (comment, keyword, string, number, title, attr, built, deletion).

Jump to

Keyboard shortcuts

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