1package lexers
 2
 3import (
 4	. "github.com/alecthomas/chroma/v2" // nolint
 5)
 6
 7// Gemtext lexer.
 8var Gemtext = Register(MustNewLexer(
 9	&Config{
10		Name:      "Gemtext",
11		Aliases:   []string{"gemtext", "gmi", "gmni", "gemini"},
12		Filenames: []string{"*.gmi", "*.gmni", "*.gemini"},
13		MimeTypes: []string{"text/gemini"},
14	},
15	gemtextRules,
16))
17
18func gemtextRules() Rules {
19	return Rules{
20		"root": {
21			{`^(#[^#].+\r?\n)`, ByGroups(GenericHeading), nil},
22			{`^(#{2,3}.+\r?\n)`, ByGroups(GenericSubheading), nil},
23			{`^(\* )(.+\r?\n)`, ByGroups(Keyword, Text), nil},
24			{`^(>)(.+\r?\n)`, ByGroups(Keyword, GenericEmph), nil},
25			{"^(```\\r?\\n)([\\w\\W]*?)(^```)(.+\\r?\\n)?", ByGroups(String, Text, String, Comment), nil},
26			{
27				"^(```)(\\w+)(\\r?\\n)([\\w\\W]*?)(^```)(.+\\r?\\n)?",
28				UsingByGroup(2, 4, String, String, String, Text, String, Comment),
29				nil,
30			},
31			{"^(```)(.+\\r?\\n)([\\w\\W]*?)(^```)(.+\\r?\\n)?", ByGroups(String, String, Text, String, Comment), nil},
32			{`^(=>)(\s*)([^\s]+)(\s*)$`, ByGroups(Keyword, Text, NameAttribute, Text), nil},
33			{`^(=>)(\s*)([^\s]+)(\s+)(.+)$`, ByGroups(Keyword, Text, NameAttribute, Text, NameTag), nil},
34			{`(.|(?:\r?\n))`, ByGroups(Text), nil},
35		},
36	}
37}