Versions in this module Expand all Collapse all v2 v2.19.0 Jun 19, 2025 Changes in this version + const Date + const Number + const NumberBin + const NumberFloat + const NumberHex + const NumberInteger + const NumberIntegerLong + const NumberOct + const String + const StringAffix + const StringBacktick + const StringChar + const StringDelimiter + const StringDoc + const StringDouble + const StringEscape + const StringHeredoc + const StringInterpol + const StringOther + const StringRegex + const StringSingle + const StringSymbol + const Whitespace + var ANSI2RGB = map[string]string + var ErrNotSerialisable = fmt.Errorf("not serialisable") + var StandardTypes = map[TokenType]string + func Marshal(l *RegexLexer) ([]byte, error) + func SplitTokensIntoLines(tokens []Token) (out [][]Token) + func Stringify(tokens ...Token) string + func TokenTypeStrings() []string + func Words(prefix, suffix string, words ...string) string + type AnalyseConfig struct + First bool + Regexes []RegexConfig + type Analyser interface + AnalyseText func(text string) float32 + type Colour int32 + func MustParseColour(colour string) Colour + func NewColour(r, g, b uint8) Colour + func ParseColour(colour string) Colour + func (c Colour) Blue() uint8 + func (c Colour) Brighten(factor float64) Colour + func (c Colour) BrightenOrDarken(factor float64) Colour + func (c Colour) Brightness() float64 + func (c Colour) ClampBrightness(min, max float64) Colour + func (c Colour) Distance(e2 Colour) float64 + func (c Colour) GoString() string + func (c Colour) Green() uint8 + func (c Colour) IsSet() bool + func (c Colour) Red() uint8 + func (c Colour) String() string + type Colours []Colour + func (c Colours) Len() int + func (c Colours) Less(i, j int) bool + func (c Colours) Swap(i, j int) + type CompiledRule struct + Regexp *regexp2.Regexp + type CompiledRules map[string][]*CompiledRule + type Config struct + AliasFilenames []string + Aliases []string + Analyse *AnalyseConfig + CaseInsensitive bool + DotAll bool + EnsureNL bool + Filenames []string + MimeTypes []string + Name string + NotMultiline bool + Priority float32 + type Emitter interface + Emit func(groups []string, state *LexerState) Iterator + func ByGroupNames(emitters map[string]Emitter) Emitter + func ByGroups(emitters ...Emitter) Emitter + func Using(lexer string) Emitter + func UsingByGroup(sublexerNameGroup, codeGroup int, emitters ...Emitter) Emitter + func UsingLexer(lexer Lexer) Emitter + func UsingSelf(stateName string) Emitter + type EmitterFunc func(groups []string, state *LexerState) Iterator + func (e EmitterFunc) Emit(groups []string, state *LexerState) Iterator + type Emitters []Emitter + func (b *Emitters) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error + func (b Emitters) MarshalXML(e *xml.Encoder, start xml.StartElement) error + type Formatter interface + Format func(w io.Writer, style *Style, iterator Iterator) error + func RecoveringFormatter(formatter Formatter) Formatter + type FormatterFunc func(w io.Writer, style *Style, iterator Iterator) error + func (f FormatterFunc) Format(w io.Writer, s *Style, it Iterator) (err error) + type Iterator func() Token + func Concaterator(iterators ...Iterator) Iterator + func Literator(tokens ...Token) Iterator + func (i Iterator) Stdlib() func(yield func(Token) bool) + func (i Iterator) Tokens() []Token + type Lexer interface + AnalyseText func(text string) float32 + Config func() *Config + SetAnalyser func(analyser func(text string) float32) Lexer + SetRegistry func(registry *LexerRegistry) Lexer + Tokenise func(options *TokeniseOptions, text string) (Iterator, error) + func Coalesce(lexer Lexer) Lexer + func DelegatingLexer(root Lexer, language Lexer) Lexer + func RemappingLexer(lexer Lexer, mapper func(Token) []Token) Lexer + func TypeRemappingLexer(lexer Lexer, mapping TypeMapping) Lexer + type LexerMutator interface + MutateLexer func(rules CompiledRules, state string, rule int) error + type LexerRegistry struct + Lexers Lexers + func NewLexerRegistry() *LexerRegistry + func (l *LexerRegistry) Aliases(skipWithoutAliases bool) []string + func (l *LexerRegistry) Analyse(text string) Lexer + func (l *LexerRegistry) Get(name string) Lexer + func (l *LexerRegistry) Match(filename string) Lexer + func (l *LexerRegistry) MatchMimeType(mimeType string) Lexer + func (l *LexerRegistry) Names(withAliases bool) []string + func (l *LexerRegistry) Register(lexer Lexer) Lexer + type LexerState struct + Groups []string + Lexer *RegexLexer + MutatorContext map[interface{}]interface{} + NamedGroups map[string]string + Pos int + Registry *LexerRegistry + Rule int + Rules CompiledRules + Stack []string + State string + Text []rune + func (l *LexerState) Get(key interface{}) interface{} + func (l *LexerState) Iterator() Token + func (l *LexerState) Set(key interface{}, value interface{}) + type Lexers []Lexer + func (l Lexers) Len() int + func (l Lexers) Less(i, j int) bool + func (l Lexers) Swap(i, j int) + type Mutator interface + Mutate func(state *LexerState) error + func Combined(states ...string) Mutator + func Mutators(modifiers ...Mutator) Mutator + func Pop(n int) Mutator + func Push(states ...string) Mutator + type MutatorFunc func(state *LexerState) error + func (m MutatorFunc) Mutate(state *LexerState) error + type PrioritisedLexers []Lexer + func (l PrioritisedLexers) Len() int + func (l PrioritisedLexers) Less(i, j int) bool + func (l PrioritisedLexers) Swap(i, j int) + type RegexConfig struct + Pattern string + Score float32 + type RegexLexer struct + func MustNewLexer(config *Config, rules func() Rules) *RegexLexer + func MustNewXMLLexer(from fs.FS, path string) *RegexLexer + func NewLexer(config *Config, rulesFunc func() Rules) (*RegexLexer, error) + func NewXMLLexer(from fs.FS, path string) (*RegexLexer, error) + func Unmarshal(data []byte) (*RegexLexer, error) + func (r *RegexLexer) AnalyseText(text string) float32 + func (r *RegexLexer) Config() *Config + func (r *RegexLexer) MustRules() Rules + func (r *RegexLexer) Rules() (Rules, error) + func (r *RegexLexer) SetAnalyser(analyser func(text string) float32) Lexer + func (r *RegexLexer) SetConfig(config *Config) *RegexLexer + func (r *RegexLexer) SetRegistry(registry *LexerRegistry) Lexer + func (r *RegexLexer) String() string + func (r *RegexLexer) Tokenise(options *TokeniseOptions, text string) (Iterator, error) + func (r *RegexLexer) Trace(trace bool) *RegexLexer + type Rule struct + Mutator Mutator + Pattern string + Type Emitter + func Default(mutators ...Mutator) Rule + func Include(state string) Rule + func (r *Rule) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error + func (r Rule) MarshalXML(e *xml.Encoder, _ xml.StartElement) error + type Rules map[string][]Rule + func (r *Rules) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error + func (r Rules) Clone() Rules + func (r Rules) MarshalXML(e *xml.Encoder, _ xml.StartElement) error + func (r Rules) Merge(rules Rules) Rules + func (r Rules) Rename(oldRule, newRule string) Rules + type SerialisableEmitter interface + EmitterKind func() string + type SerialisableMutator interface + MutatorKind func() string + type Style struct + Name string + func MustNewStyle(name string, entries StyleEntries) *Style + func MustNewXMLStyle(r io.Reader) *Style + func NewStyle(name string, entries StyleEntries) (*Style, error) + func NewXMLStyle(r io.Reader) (*Style, error) + func (s *Style) Builder() *StyleBuilder + func (s *Style) Get(ttype TokenType) StyleEntry + func (s *Style) Has(ttype TokenType) bool + func (s *Style) MarshalXML(e *xml.Encoder, start xml.StartElement) error + func (s *Style) Types() []TokenType + func (s *Style) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error + type StyleBuilder struct + func NewStyleBuilder(name string) *StyleBuilder + func (s *StyleBuilder) Add(ttype TokenType, entry string) *StyleBuilder + func (s *StyleBuilder) AddAll(entries StyleEntries) *StyleBuilder + func (s *StyleBuilder) AddEntry(ttype TokenType, entry StyleEntry) *StyleBuilder + func (s *StyleBuilder) Build() (*Style, error) + func (s *StyleBuilder) Get(ttype TokenType) StyleEntry + func (s *StyleBuilder) Transform(transform func(StyleEntry) StyleEntry) *StyleBuilder + type StyleEntries map[TokenType]string + type StyleEntry struct + Background Colour + Bold Trilean + Border Colour + Colour Colour + Italic Trilean + NoInherit bool + Underline Trilean + func MustParseStyleEntry(entry string) StyleEntry + func ParseStyleEntry(entry string) (StyleEntry, error) + func (s StyleEntry) Inherit(ancestors ...StyleEntry) StyleEntry + func (s StyleEntry) IsZero() bool + func (s StyleEntry) MarshalText() ([]byte, error) + func (s StyleEntry) String() string + func (s StyleEntry) Sub(e StyleEntry) StyleEntry + type Token struct + Type TokenType + Value string + var EOF Token + func Tokenise(lexer Lexer, options *TokeniseOptions, text string) ([]Token, error) + func (t *Token) Clone() Token + func (t *Token) GoString() string + func (t *Token) String() string + type TokenType int + const Background + const CodeLine + const Comment + const CommentHashbang + const CommentMultiline + const CommentPreproc + const CommentPreprocFile + const CommentSingle + const CommentSpecial + const EOFType + const Error + const Generic + const GenericDeleted + const GenericEmph + const GenericError + const GenericHeading + const GenericInserted + const GenericOutput + const GenericPrompt + const GenericStrong + const GenericSubheading + const GenericTraceback + const GenericUnderline + const Ignore + const Keyword + const KeywordConstant + const KeywordDeclaration + const KeywordNamespace + const KeywordPseudo + const KeywordReserved + const KeywordType + const Line + const LineHighlight + const LineLink + const LineNumbers + const LineNumbersTable + const LineTable + const LineTableTD + const Literal + const LiteralDate + const LiteralNumber + const LiteralNumberBin + const LiteralNumberByte + const LiteralNumberFloat + const LiteralNumberHex + const LiteralNumberInteger + const LiteralNumberIntegerLong + const LiteralNumberOct + const LiteralOther + const LiteralString + const LiteralStringAffix + const LiteralStringAtom + const LiteralStringBacktick + const LiteralStringBoolean + const LiteralStringChar + const LiteralStringDelimiter + const LiteralStringDoc + const LiteralStringDouble + const LiteralStringEscape + const LiteralStringHeredoc + const LiteralStringInterpol + const LiteralStringName + const LiteralStringOther + const LiteralStringRegex + const LiteralStringSingle + const LiteralStringSymbol + const Name + const NameAttribute + const NameBuiltin + const NameBuiltinPseudo + const NameClass + const NameConstant + const NameDecorator + const NameEntity + const NameException + const NameFunction + const NameFunctionMagic + const NameKeyword + const NameLabel + const NameNamespace + const NameOperator + const NameOther + const NameProperty + const NamePseudo + const NameTag + const NameVariable + const NameVariableAnonymous + const NameVariableClass + const NameVariableGlobal + const NameVariableInstance + const NameVariableMagic + const None + const Operator + const OperatorWord + const Other + const PreWrapper + const Punctuation + const Text + const TextPunctuation + const TextSymbol + const TextWhitespace + func TokenTypeString(s string) (TokenType, error) + func TokenTypeValues() []TokenType + func (i *TokenType) UnmarshalText(text []byte) error + func (i TokenType) IsATokenType() bool + func (i TokenType) MarshalText() ([]byte, error) + func (i TokenType) String() string + func (t *TokenType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error + func (t TokenType) Category() TokenType + func (t TokenType) Emit(groups []string, _ *LexerState) Iterator + func (t TokenType) EmitterKind() string + func (t TokenType) InCategory(other TokenType) bool + func (t TokenType) InSubCategory(other TokenType) bool + func (t TokenType) MarshalXML(e *xml.Encoder, start xml.StartElement) error + func (t TokenType) Parent() TokenType + func (t TokenType) SubCategory() TokenType + type TokeniseOptions struct + EnsureLF bool + Nested bool + State string + type Trilean uint8 + const No + const Pass + const Yes + func (t Trilean) Prefix(s string) string + func (t Trilean) String() string + type TypeMapping []struct v2.19.0-mpl-final Jun 23, 2025 v2.19.0-mpl Jun 19, 2025 Other modules containing this package github.com/crowyy03/chroma