1 package lexers
2
3 import (
4 . "github.com/alecthomas/chroma/v2"
5 )
6
7
8 var Org = Register(MustNewLexer(
9 &Config{
10 Name: "Org Mode",
11 Aliases: []string{"org", "orgmode"},
12 Filenames: []string{"*.org"},
13 MimeTypes: []string{"text/org"},
14 },
15 orgRules,
16 ))
17
18 func orgRules() Rules {
19 return Rules{
20 "root": {
21 {`^# .*$`, Comment, nil},
22
23 {`^(\*)( COMMENT)( .*)$`, ByGroups(GenericHeading, NameEntity, GenericStrong), nil},
24 {`^(\*\*+)( COMMENT)( .*)$`, ByGroups(GenericSubheading, NameEntity, Text), nil},
25 {`^(\*)( DONE)( .*)$`, ByGroups(GenericHeading, LiteralStringRegex, GenericStrong), nil},
26 {`^(\*\*+)( DONE)( .*)$`, ByGroups(GenericSubheading, LiteralStringRegex, Text), nil},
27 {`^(\*)( TODO)( .*)$`, ByGroups(GenericHeading, Error, GenericStrong), nil},
28 {`^(\*\*+)( TODO)( .*)$`, ByGroups(GenericSubheading, Error, Text), nil},
29 {`^(\*)( .+?)( :[a-zA-Z0-9_@:]+:)$`, ByGroups(GenericHeading, GenericStrong, GenericEmph), nil},
30 {`^(\*)( .+)$`, ByGroups(GenericHeading, GenericStrong), nil},
31 {`^(\*\*+)( .+?)( :[a-zA-Z0-9_@:]+:)$`, ByGroups(GenericSubheading, Text, GenericEmph), nil},
32 {`^(\*\*+)( .+)$`, ByGroups(GenericSubheading, Text), nil},
33
34 {`^( *)([+-] )(\[[ X]\])( .+)$`, ByGroups(Text, Keyword, Keyword, UsingSelf("inline")), nil},
35 {`^( +)(\* )(\[[ X]\])( .+)$`, ByGroups(Text, Keyword, Keyword, UsingSelf("inline")), nil},
36
37 {`^( *)([+-] )([^ \n]+ ::)( .+)$`, ByGroups(Text, Keyword, Keyword, UsingSelf("inline")), nil},
38 {`^( +)(\* )([^ \n]+ ::)( .+)$`, ByGroups(Text, Keyword, Keyword, UsingSelf("inline")), nil},
39
40 {`^( *)([+-] )(.+)$`, ByGroups(Text, Keyword, UsingSelf("inline")), nil},
41 {`^( +)(\* )(.+)$`, ByGroups(Text, Keyword, UsingSelf("inline")), nil},
42
43 {`^( *)([0-9]+[.)])( \[@[0-9]+\])( .+)$`, ByGroups(Text, Keyword, GenericEmph, UsingSelf("inline")), nil},
44 {`^( *)([0-9]+[.)])( .+)$`, ByGroups(Text, Keyword, UsingSelf("inline")), nil},
45
46 {`(?i)^( *#\+begin: )([^ ]+)([\w\W]*?\n)([\w\W]*?)(^ *#\+end: *$)`, ByGroups(Comment, CommentSpecial, Comment, UsingSelf("inline"), Comment), nil},
47
48
49 {`(?i)^( *#\+begin_comment *\n)([\w\W]*?)(^ *#\+end_comment *$)`, ByGroups(Comment, Comment, Comment), nil},
50
51 {
52 `(?i)^( *#\+begin_src )([^ \n]+)(.*?\n)([\w\W]*?)(^ *#\+end_src *$)`,
53 UsingByGroup(2, 4, Comment, CommentSpecial, Comment, Text, Comment),
54 nil,
55 },
56
57 {
58 `(?i)^( *#\+begin_export )(\w+)( *\n)([\w\W]*?)(^ *#\+end_export *$)`,
59 UsingByGroup(2, 4, Comment, CommentSpecial, Text, Text, Comment),
60 nil,
61 },
62
63 {`(?i)^( *#\+begin_)(\w+)( *\n)([\w\W]*?)(^ *#\+end_\2)( *$)`, ByGroups(Comment, Comment, Text, Text, Comment, Text), nil},
64
65 {`^(#\+\w+)(:.*)$`, ByGroups(CommentSpecial, Comment), nil},
66
67 {`(?i)^( *:\w+: *\n)([\w\W]*?)(^ *:end: *$)`, ByGroups(Comment, CommentSpecial, Comment), nil},
68
69 {`^(.*)(\\\\)$`, ByGroups(UsingSelf("inline"), Operator), nil},
70
71 {`(?i)^( *(?:DEADLINE|SCHEDULED): )(<[^<>]+?> *)$`, ByGroups(Comment, CommentSpecial), nil},
72
73 {`(?i)^( *CLOSED: )(\[[^][]+?\] *)$`, ByGroups(Comment, CommentSpecial), nil},
74
75 Include("inline"),
76 },
77 "inline": {
78 {`(\s)*(\*[^ \n*][^*]+?[^ \n*]\*)((?=\W|\n|$))`, ByGroups(Text, GenericStrong, Text), nil},
79 {`(\s)*(/[^/]+?/)((?=\W|\n|$))`, ByGroups(Text, GenericEmph, Text), nil},
80 {`(\s)*(=[^\n=]+?=)((?=\W|\n|$))`, ByGroups(Text, NameClass, Text), nil},
81 {`(\s)*(~[^\n~]+?~)((?=\W|\n|$))`, ByGroups(Text, NameClass, Text), nil},
82 {`(\s)*(\+[^+]+?\+)((?=\W|\n|$))`, ByGroups(Text, GenericDeleted, Text), nil},
83 {`(\s)*(_[^_]+?_)((?=\W|\n|$))`, ByGroups(Text, GenericUnderline, Text), nil},
84 {`(<)([^<>]+?)(>)`, ByGroups(Text, String, Text), nil},
85 {`[{]{3}[^}]+[}]{3}`, NameBuiltin, nil},
86 {`([^[])(\[fn:)([^]]+?)(\])([^]])`, ByGroups(Text, NameBuiltinPseudo, LiteralString, NameBuiltinPseudo, Text), nil},
87
88 {`(\[\[)([^][]+?)(\]\[)([^][]+)(\]\])`, ByGroups(Text, NameAttribute, Text, NameTag, Text), nil},
89 {`(\[\[)([^][]+?)(\]\])`, ByGroups(Text, NameAttribute, Text), nil},
90 {`(<<)([^<>]+?)(>>)`, ByGroups(Text, NameAttribute, Text), nil},
91
92 {`^( *)(\|[ -].*?[ -]\|)$`, ByGroups(Text, String), nil},
93
94 {`\n`, Text, nil},
95
96 {`.`, Text, nil},
97 },
98 }
99 }
100
View as plain text