syntax

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package syntax resolves language rules and highlights source text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHighlighter

func NewHighlighter(lexer chroma.Lexer, style *chroma.Style, observers ...func(chroma.Token)) func(string) []string

NewHighlighter reuses the selected lexer. Each call independently tokenises content and returns lines with ANSI styling. Observers receive every token of the pass, including errors before restyling and the final EOF. The caller must supply a non-nil style.

On tokenisation/formatting failure or a line-count mismatch, the result is unstyled strings.Split(content, "\n"), including any trailing empty element. Observers may already have received some or all tokens when this happens. Successful output omits the trailing empty element.

Types

type Config

type Config struct {
	Aliases map[string]string `toml:"aliases" json:"aliases,omitempty"`
	Files   []FileType        `toml:"files" json:"files,omitempty"`
}

func Merge

func Merge(base, project Config) Config

Merge gives project aliases and filename rules precedence over global ones. Rules within each level keep their declaration order; the first match wins.

func (Config) ValidateNames

func (c Config) ValidateNames() error

ValidateNames catches ambiguous case variants before configuration levels merge.

type FileType

type FileType struct {
	Pattern  string `toml:"pattern" json:"pattern"`
	Language string `toml:"language" json:"language"`
}

type Rules

type Rules struct {
	// contains filtered or unexported fields
}

Rules is immutable after compilation and can be shared by concurrent renderers. A nil Rules value retains built-in language detection.

func Compile

func Compile(cfg Config) (*Rules, error)

func (*Rules) HasAlias

func (r *Rules) HasAlias(name string) bool

func (*Rules) Lexer

func (r *Rules) Lexer(name string) chroma.Lexer

Lexer resolves a fence language name, including overrides of built-in aliases.

func (*Rules) Match

func (r *Rules) Match(filename string) (chroma.Lexer, bool)

Match checks case-sensitive basename globs before the built-in filename rules.

Jump to

Keyboard shortcuts

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