Documentation
¶
Overview ¶
Package chromalexers is github.com/alecthomas/chroma/v2/lexers at v2.27.0 with one deliberate change: the lexer registry is built lazily on first use instead of at package init. Upstream's init decodes 279 embedded XML lexer configs (~6ms, ~2.7MB of allocations) on every process start, including `orb --version`; here that cost moves to the first highlight. Keep every other file byte-identical to upstream apart from the package clause and the three init() funcs converted to registration hooks below.
Index ¶
- Variables
- func Aliases(skipWithoutAliases bool) []string
- func Analyse(text string) chroma.Lexer
- func Get(name string) chroma.Lexer
- func Match(filename string) chroma.Lexer
- func MatchMimeType(mimeType string) chroma.Lexer
- func Names(withAliases bool) []string
- func PlaintextRules() chroma.Rules
- func Register(lexer chroma.Lexer) chroma.Lexer
Constants ¶
This section is empty.
Variables ¶
var Caddyfile = Register(MustNewLexer( &Config{ Name: "Caddyfile", Aliases: []string{"caddyfile", "caddy"}, Filenames: []string{"Caddyfile*"}, MimeTypes: []string{}, }, caddyfileRules, ))
Caddyfile lexer.
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.
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.
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.
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.
var Fallback chroma.Lexer = chroma.MustNewLexer(&chroma.Config{ Name: "fallback", Filenames: []string{"*"}, Priority: -1, }, PlaintextRules)
Fallback lexer if no other is found.
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.
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.
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.
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.
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.
var GoHTMLTemplate = Register(DelegatingLexer(HTML, MustNewXMLLexer( embedded, "embedded/go_template.xml", ).SetConfig( &Config{ Name: "Go HTML Template", Aliases: []string{"go-html-template"}, }, )))
var GoTextTemplate = Register(MustNewXMLLexer( embedded, "embedded/go_template.xml", ).SetConfig( &Config{ Name: "Go Text Template", Aliases: []string{"go-text-template"}, }, ))
var HTML = chroma.MustNewXMLLexer(embedded, "embedded/html.xml")
HTML lexer.
var HTTP = Register(httpBodyContentTypeLexer(MustNewLexer( &Config{ Name: "HTTP", Aliases: []string{"http"}, Filenames: []string{}, MimeTypes: []string{}, NotMultiline: true, DotAll: true, }, httpRules, )))
HTTP lexer.
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.
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.
var Markless = Register(MustNewLexer( &Config{ Name: "Markless", Aliases: []string{"mess"}, Filenames: []string{"*.mess", "*.markless"}, MimeTypes: []string{"text/x-markless"}, }, marklessRules, ))
Markless lexer.
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.
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.
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.
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.
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 Aliases ¶
Aliases of all the lexers, and skip those lexers who do not have any aliases, or show their name instead
func Get ¶
Get a Lexer by name, alias or file extension.
Note that this if there isn't an exact match on name or alias, this will call Match(), so it is not efficient.
func Match ¶
Match returns the first lexer matching filename.
Note that this iterates over all file patterns in all lexers, so it's not particularly efficient.
func MatchMimeType ¶
MatchMimeType attempts to find a lexer for the given MIME type.
func PlaintextRules ¶
PlaintextRules is used for the fallback lexer as well as the explicit plaintext lexer.
Types ¶
This section is empty.