lexers

package
v0.0.0-...-195ec3b Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT, MIT, OFL-1.1 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Caddyfile = Register(MustNewLexer(
	&Config{
		Name:      "Caddyfile",
		Aliases:   []string{"caddyfile", "caddy"},
		Filenames: []string{"Caddyfile*"},
		MimeTypes: []string{},
	},
	caddyfileRules,
))

Caddyfile lexer.

View Source
var CaddyfileDirectives = Register(MustNewLexer(
	&Config{
		Name:      "Caddyfile Directives",
		Aliases:   []string{"caddyfile-directives", "caddyfile-d", "caddy-d"},
		Filenames: []string{},
		MimeTypes: []string{},
	},
	caddyfileDirectivesRules,
))

Caddyfile directive-only lexer.

View Source
var CommonLisp = Register(TypeRemappingLexer(MustNewXMLLexer(
	embedded,
	"embedded/common_lisp.xml",
), TypeMapping{
	{NameVariable, NameFunction, clBuiltinFunctions},
	{NameVariable, Keyword, clSpecialForms},
	{NameVariable, NameBuiltin, clMacros},
	{NameVariable, Keyword, clLambdaListKeywords},
	{NameVariable, Keyword, clDeclarations},
	{NameVariable, KeywordType, clBuiltinTypes},
	{NameVariable, NameClass, clBuiltinClasses},
}))

Common Lisp lexer.

View Source
var ERB = Register(DelegatingLexer(HTML, MustNewXMLLexer(
	embedded,
	"embedded/erb.xml",
).SetConfig(
	&Config{
		Name:      "ERB",
		Aliases:   []string{"erb", "html+erb", "html+ruby", "rhtml"},
		Filenames: []string{"*.erb", "*.html.erb", "*.xml.erb", "*.rhtml"},
		MimeTypes: []string{"application/x-ruby-templating"},
		DotAll:    true,
	},
).SetAnalyser(func(text string) float32 {
	if strings.Contains(text, "<%=") && strings.Contains(text, "%>") {
		return 0.4
	}
	if strings.Contains(text, "<%") {
		return 0.1
	}
	return 0.0
})))

ERB lexer is Ruby embedded in HTML.

View Source
var EmacsLisp = Register(TypeRemappingLexer(MustNewXMLLexer(
	embedded,
	"embedded/emacslisp.xml",
), TypeMapping{
	{NameVariable, NameFunction, emacsBuiltinFunction},
	{NameVariable, NameBuiltin, emacsSpecialForms},
	{NameVariable, NameException, emacsErrorKeywords},
	{NameVariable, NameBuiltin, append(emacsBuiltinFunctionHighlighted, emacsMacros...)},
	{NameVariable, KeywordPseudo, emacsLambdaListKeywords},
}))

EmacsLisp lexer.

View Source
var Fallback chroma.Lexer = chroma.MustNewLexer(&chroma.Config{
	Name:      "fallback",
	Filenames: []string{"*"},
	Priority:  -1,
}, PlaintextRules)

Fallback lexer if no other is found.

View Source
var Gemtext = Register(MustNewLexer(
	&Config{
		Name:      "Gemtext",
		Aliases:   []string{"gemtext", "gmi", "gmni", "gemini"},
		Filenames: []string{"*.gmi", "*.gmni", "*.gemini"},
		MimeTypes: []string{"text/gemini"},
	},
	gemtextRules,
))

Gemtext lexer.

View Source
var Genshi = Register(MustNewLexer(
	&Config{
		Name:         "Genshi",
		Aliases:      []string{"genshi", "kid", "xml+genshi", "xml+kid"},
		Filenames:    []string{"*.kid"},
		MimeTypes:    []string{"application/x-genshi", "application/x-kid"},
		NotMultiline: true,
		DotAll:       true,
	},
	genshiMarkupRules,
))

Genshi lexer.

View Source
var GenshiHTMLTemplate = Register(MustNewLexer(
	&Config{
		Name:         "Genshi HTML",
		Aliases:      []string{"html+genshi", "html+kid"},
		Filenames:    []string{},
		MimeTypes:    []string{"text/html+genshi"},
		NotMultiline: true,
		DotAll:       true,
	},
	genshiMarkupRules,
))

Html+Genshi lexer.

View Source
var GenshiText = Register(MustNewLexer(
	&Config{
		Name:      "Genshi Text",
		Aliases:   []string{"genshitext"},
		Filenames: []string{},
		MimeTypes: []string{"application/x-genshi-text", "text/x-genshi"},
	},
	genshiTextRules,
))

Genshi Text lexer.

View Source
var Go = Register(MustNewLexer(
	&Config{
		Name:      "Go",
		Aliases:   []string{"go", "golang"},
		Filenames: []string{"*.go"},
		MimeTypes: []string{"text/x-gosrc"},
	},
	goRules,
).SetAnalyser(func(text string) float32 {
	if strings.Contains(text, "fmt.") && strings.Contains(text, "package ") {
		return 0.5
	}
	if strings.Contains(text, "package ") {
		return 0.1
	}
	return 0.0
}))

Go lexer.

View Source
var GoHTMLTemplate = Register(DelegatingLexer(HTML, MustNewXMLLexer(
	embedded,
	"embedded/go_template.xml",
).SetConfig(
	&Config{
		Name:    "Go HTML Template",
		Aliases: []string{"go-html-template"},
	},
)))
View Source
var GoTextTemplate = Register(MustNewXMLLexer(
	embedded,
	"embedded/go_template.xml",
).SetConfig(
	&Config{
		Name:    "Go Text Template",
		Aliases: []string{"go-text-template"},
	},
))
View Source
var HTML = chroma.MustNewXMLLexer(embedded, "embedded/html.xml")

HTML lexer.

View Source
var HTTP = Register(httpBodyContentTypeLexer(MustNewLexer(
	&Config{
		Name:         "HTTP",
		Aliases:      []string{"http"},
		Filenames:    []string{},
		MimeTypes:    []string{},
		NotMultiline: true,
		DotAll:       true,
	},
	httpRules,
)))

HTTP lexer.

View Source
var Haxe = Register(MustNewLexer(
	&Config{
		Name:      "Haxe",
		Aliases:   []string{"hx", "haxe", "hxsl"},
		Filenames: []string{"*.hx", "*.hxsl"},
		MimeTypes: []string{"text/haxe", "text/x-haxe", "text/x-hx"},
		DotAll:    true,
	},
	haxeRules,
))

Haxe lexer.

View Source
var Markdown = Register(&markdownLexer{Lexer: MustNewLexer(
	&Config{
		Name:      "markdown",
		Aliases:   []string{"md", "mkd"},
		Filenames: []string{"*.md", "*.mkd", "*.markdown"},
		MimeTypes: []string{"text/x-markdown"},
	},
	markdownRules,
)})

Markdown lexer with YAML frontmatter and HTML comment support.

View Source
var Markless = Register(MustNewLexer(
	&Config{
		Name:      "Markless",
		Aliases:   []string{"mess"},
		Filenames: []string{"*.mess", "*.markless"},
		MimeTypes: []string{"text/x-markless"},
	},
	marklessRules,
))

Markless lexer.

View Source
var Raku Lexer = Register(MustNewLexer(
	&Config{
		Name:    "Raku",
		Aliases: []string{"perl6", "pl6", "raku"},
		Filenames: []string{
			"*.pl", "*.pm", "*.nqp", "*.p6", "*.6pl", "*.p6l", "*.pl6", "*.6pm",
			"*.p6m", "*.pm6", "*.t", "*.raku", "*.rakumod", "*.rakutest", "*.rakudoc",
		},
		MimeTypes: []string{
			"text/x-perl6", "application/x-perl6",
			"text/x-raku", "application/x-raku",
		},
		DotAll: true,
	},
	rakuRules,
))

Raku lexer.

View Source
var Restructuredtext = Register(MustNewLexer(
	&Config{
		Name:      "reStructuredText",
		Aliases:   []string{"rst", "rest", "restructuredtext"},
		Filenames: []string{"*.rst", "*.rest"},
		MimeTypes: []string{"text/x-rst", "text/prs.fallenstein.rst"},
	},
	restructuredtextRules,
))

Restructuredtext lexer.

View Source
var Svelte = Register(DelegatingLexer(HTML, MustNewLexer(
	&Config{
		Name:      "Svelte",
		Aliases:   []string{"svelte"},
		Filenames: []string{"*.svelte"},
		MimeTypes: []string{"application/x-svelte"},
		DotAll:    true,
	},
	svelteRules,
)))

Svelte lexer.

View Source
var Typoscript = Register(MustNewLexer(
	&Config{
		Name:      "TypoScript",
		Aliases:   []string{"typoscript"},
		Filenames: []string{"*.ts"},
		MimeTypes: []string{"text/x-typoscript"},
		DotAll:    true,
		Priority:  0.1,
	},
	typoscriptRules,
))

Typoscript lexer.

View Source
var YAMLJinja = Register(DelegatingLexer(
	MustNewXMLLexer(embedded, "embedded/yaml.xml"),
	MustNewXMLLexer(embedded, "embedded/django_jinja.xml").SetConfig(
		&Config{
			Name:      "YAML+Jinja",
			Aliases:   []string{"yaml+jinja", "salt", "sls", "ansible"},
			Filenames: []string{"*.sls"},
			MimeTypes: []string{"text/x-yaml+jinja", "text/x-sls"},
			DotAll:    true,
		},
	),
))

YAML+Jinja is YAML with Jinja templating embedded. Used by Ansible playbooks and Salt SLS files.

Functions

func Analyse

func Analyse(text string) chroma.Lexer

Analyse text content and return the "best" lexer.

func Get

func Get(name string) chroma.Lexer

Get a Lexer by name, alias or file extension.

func Match

func Match(filename string) chroma.Lexer

Match returns the first lexer matching filename.

func MatchMimeType

func MatchMimeType(mimeType string) chroma.Lexer

MatchMimeType attempts to find a lexer for the given MIME type.

func Names

func Names(withAliases bool) []string

Names of all lexers, optionally including aliases.

func PlaintextRules

func PlaintextRules() chroma.Rules

PlaintextRules is used for the fallback lexer as well as the explicit plaintext lexer.

func Register

func Register(lexer chroma.Lexer) chroma.Lexer

Register a Lexer; before the registry exists it is queued.

Types

This section is empty.

Jump to

Keyboard shortcuts

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