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