1package lexers
2
3import (
4 . "github.com/alecthomas/chroma/v2" // nolint
5)
6
7// Markless lexer.
8var Markless = Register(MustNewLexer(
9 &Config{
10 Name: "Markless",
11 Aliases: []string{"mess"},
12 Filenames: []string{"*.mess", "*.markless"},
13 MimeTypes: []string{"text/x-markless"},
14 },
15 marklessRules,
16))
17
18func marklessRules() Rules {
19 return Rules{
20 "root": {
21 Include("block"),
22 },
23 // Block directives
24 "block": {
25 Include("header"),
26 Include("ordered-list"),
27 Include("unordered-list"),
28 Include("code-block"),
29 Include("blockquote"),
30 Include("blockquote-header"),
31 Include("align"),
32 Include("comment"),
33 Include("instruction"),
34 Include("embed"),
35 Include("footnote"),
36 Include("horizontal-rule"),
37 Include("paragraph"),
38 },
39 "header": {
40 {`(# )(.*)$`, ByGroups(Keyword, GenericHeading), Push("inline")},
41 {`(##+)(.*)$`, ByGroups(Keyword, GenericSubheading), Push("inline")},
42 },
43 "ordered-list": {
44 {`([0-9]+\.)`, Keyword, nil},
45 },
46 "unordered-list": {
47 {`(- )`, Keyword, nil},
48 },
49 "code-block": {
50 {`(::+)( *)(\w*)([^\n]*)(\n)([\w\W]*?)(^\1$)`, UsingByGroup(3, 6, Keyword, TextWhitespace, NameFunction, String, TextWhitespace, Text, Keyword), nil},
51 },
52 "blockquote": {
53 {`(\| )(.*)$`, ByGroups(Keyword, GenericInserted), nil},
54 },
55 "blockquote-header": {
56 {`(~ )([^|\n]+)(\| )(.*?\n)`, ByGroups(Keyword, NameEntity, Keyword, GenericInserted), Push("inline-blockquote")},
57 {`(~ )(.*)$`, ByGroups(Keyword, NameEntity), nil},
58 },
59 "inline-blockquote": {
60 {`^( +)(\| )(.*$)`, ByGroups(TextWhitespace, Keyword, GenericInserted), nil},
61 Default(Pop(1)),
62 },
63 "align": {
64 {`(\|\|)|(\|<)|(\|>)|(><)`, Keyword, nil},
65 },
66 "comment": {
67 {`(;[; ]).*?$`, CommentSingle, nil},
68 },
69 "instruction": {
70 {`(! )([^ ]+)(.+?)$`, ByGroups(Keyword, NameFunction, NameVariable), nil},
71 },
72 "embed": {
73 {`(\[ )([^ ]+)( )([^,]+)`, ByGroups(Keyword, NameFunction, TextWhitespace, String), Push("embed-options")},
74 },
75 "embed-options": {
76 {`\\.`, Text, nil},
77 {`,`, Punctuation, nil},
78 {`\]?$`, Keyword, Pop(1)},
79 // Generic key or key/value pair
80 {`( *)([^, \]]+)([^,\]]+)?`, ByGroups(TextWhitespace, NameFunction, String), nil},
81 {`.`, Text, nil},
82 },
83 "footnote": {
84 {`(\[)([0-9]+)(\])`, ByGroups(Keyword, NameVariable, Keyword), Push("inline")},
85 },
86 "horizontal-rule": {
87 {`(==+)$`, LiteralOther, nil},
88 },
89 "paragraph": {
90 {` *`, TextWhitespace, Push("inline")},
91 },
92 // Inline directives
93 "inline": {
94 Include("escapes"),
95 Include("dashes"),
96 Include("newline"),
97 Include("italic"),
98 Include("underline"),
99 Include("bold"),
100 Include("strikethrough"),
101 Include("code"),
102 Include("compound"),
103 Include("footnote-reference"),
104 Include("subtext"),
105 Include("subtext"),
106 Include("url"),
107 {`.`, Text, nil},
108 {`\n`, TextWhitespace, Pop(1)},
109 },
110 "escapes": {
111 {`\\.`, Text, nil},
112 },
113 "dashes": {
114 {`-{2,3}`, TextPunctuation, nil},
115 },
116 "newline": {
117 {`-/-`, TextWhitespace, nil},
118 },
119 "italic": {
120 {`(//)(.*?)(\1)`, ByGroups(Keyword, GenericEmph, Keyword), nil},
121 },
122 "underline": {
123 {`(__)(.*?)(\1)`, ByGroups(Keyword, GenericUnderline, Keyword), nil},
124 },
125 "bold": {
126 {`(\*\*)(.*?)(\1)`, ByGroups(Keyword, GenericStrong, Keyword), nil},
127 },
128 "strikethrough": {
129 {`(<-)(.*?)(->)`, ByGroups(Keyword, GenericDeleted, Keyword), nil},
130 },
131 "code": {
132 {"(``+)(.*?)(\\1)", ByGroups(Keyword, LiteralStringBacktick, Keyword), nil},
133 },
134 "compound": {
135 {`(''+)(.*?)(''\()`, ByGroups(Keyword, UsingSelf("inline"), Keyword), Push("compound-options")},
136 },
137 "compound-options": {
138 {`\\.`, Text, nil},
139 {`,`, Punctuation, nil},
140 {`\)`, Keyword, Pop(1)},
141 // Hex Color
142 {` *#[0-9A-Fa-f]{3,6} *`, LiteralNumberHex, nil},
143 // Named Color
144 {` *(indian-red|light-coral|salmon|dark-salmon|light-salmon|crimson|red|firebrick|dark-red|pink|light-pink|hot-pink|deep-pink|medium-violet-red|pale-violet-red|coral|tomato|orange-red|dark-orange|orange|gold|yellow|light-yellow|lemon-chiffon|light-goldenrod-yellow|papayawhip|moccasin|peachpuff|pale-goldenrod|khaki|dark-khaki|lavender|thistle|plum|violet|orchid|fuchsia|magenta|medium-orchid|medium-purple|rebecca-purple|blue-violet|dark-violet|dark-orchid|dark-magenta|purple|indigo|slate-blue|dark-slate-blue|medium-slate-blue|green-yellow|chartreuse|lawn-green|lime|lime-green|pale-green|light-green|medium-spring-green|spring-green|medium-sea-green|sea-green|forest-green|green|dark-green|yellow-green|olive-drab|olive|dark-olive-green|medium-aquamarine|dark-sea-green|light-sea-green|dark-cyan|teal|aqua|cyan|light-cyan|pale-turquoise|aquamarine|turquoise|medium-turquoise|dark-turquoise|cadet-blue|steel-blue|light-steel-blue|powder-blue|light-blue|sky-blue|light-sky-blue|deep-sky-blue|dodger-blue|cornflower-blue|royal-blue|blue|medium-blue|dark-blue|navy|midnight-blue|cornsilk|blanched-almond|bisque|navajo-white|wheat|burlywood|tan|rosy-brown|sandy-brown|goldenrod|dark-goldenrod|peru|chocolate|saddle-brown|sienna|brown|maroon|white|snow|honeydew|mintcream|azure|alice-blue|ghost-white|white-smoke|seashell|beige|oldlace|floral-white|ivory|antique-white|linen|lavenderblush|mistyrose|gainsboro|light-gray|silver|dark-gray|gray|dim-gray|light-slate-gray|slate-gray|dark-slate-gray) *`, LiteralOther, nil},
145 // Named size
146 {` *(microscopic|tiny|small|normal|big|large|huge|gigantic) *`, NameTag, nil},
147 // Options
148 {` *(bold|italic|underline|strikethrough|subtext|supertext|spoiler) *`, NameBuiltin, nil},
149 // URL. Note the missing ) and , in the match.
150 {` *\w[-\w+.]*://[\w$\-_.+!*'(&/:;=?@z%#\\]+ *`, String, nil},
151 // Generic key or key/value pair
152 {`( *)([^, )]+)( [^,)]+)?`, ByGroups(TextWhitespace, NameFunction, String), nil},
153 {`.`, Text, nil},
154 },
155 "footnote-reference": {
156 {`(\[)([0-9]+)(\])`, ByGroups(Keyword, NameVariable, Keyword), nil},
157 },
158 "subtext": {
159 {`(v\()(.*?)(\))`, ByGroups(Keyword, UsingSelf("inline"), Keyword), nil},
160 },
161 "supertext": {
162 {`(\^\()(.*?)(\))`, ByGroups(Keyword, UsingSelf("inline"), Keyword), nil},
163 },
164 "url": {
165 {`\w[-\w+.]*://[\w\$\-_.+!*'()&,/:;=?@z%#\\]+`, String, nil},
166 },
167 }
168}