@@ -10,8 +10,10 @@ import std.array;
1010import dparse.lexer;
1111
1212// http://ethanschoonover.com/solarized
13- void highlight (R)(ref R tokens, string fileName)
13+ void highlight (R)(ref R tokens, string fileName, string themeName )
1414{
15+ immutable (Theme)* theme = getTheme(themeName);
16+
1517 stdout.writeln(q" [
1618<!DOCTYPE html>
1719<html>
@@ -20,17 +22,19 @@ void highlight(R)(ref R tokens, string fileName)
2022 stdout.writeln(" <title>" , fileName, " </title>" );
2123 stdout.writeln(q" [</head>
2224<body>
23- <style type=" text/ css" >
24- html { background-color: #fdf6e3; color: #002b36; }
25- .kwrd { color: #b58900; font-weight: bold; }
26- .com { color: #93a1a1; font-style: italic; }
27- .num { color: #dc322f; font-weight: bold; }
28- .str { color: #2aa198; font-style: italic; }
29- .op { color: #586e75; font-weight: bold; }
30- .type { color: #268bd2; font-weight: bold; }
31- .cons { color: #859900; font-weight: bold; }
25+ <style type=" text/ css" >]" );
26+ stdout.writefln("
27+ html { background-color: %s; color: %s; }
28+ .kwrd { color: %s; font-weight: bold; }
29+ .com { color: %s; font-style: italic; }
30+ .num { color: %s; font-weight: bold; }
31+ .str { color: %s; font-style: italic; }
32+ .op { color: %s; font-weight: bold; }
33+ .type { color: %s; font-weight: bold; }
34+ .cons { color: %s; font-weight: bold; }
3235</style>
33- <pre>]" );
36+ <pre>" , theme.bg, theme.fg, theme.kwrd, theme.com, theme.num, theme.str,
37+ theme.op, theme.type, theme.cons);
3438
3539 while (! tokens.empty)
3640 {
@@ -76,3 +80,37 @@ void writeSpan(string cssClass, string value)
7680 stdout.write(` <span class="` , cssClass, ` ">` , value.replace(" &" ,
7781 " &" ).replace(" <" , " <" ), ` </span>` );
7882}
83+
84+ struct Theme
85+ {
86+ string bg;
87+ string fg;
88+ string kwrd;
89+ string com;
90+ string num;
91+ string str;
92+ string op;
93+ string type;
94+ string cons;
95+ }
96+
97+ immutable (Theme)* getTheme (string themeName)
98+ {
99+ immutable Theme[string ] themes = [
100+ " solarized" : Theme(" #fdf6e3" , " #002b36" , " #b58900" , " #93a1a1" , " #dc322f" , " #2aa198" , " #586e75" ,
101+ " #268bd2" , " #859900" ),
102+ " solarized-dark" : Theme(" #002b36" , " #fdf6e3" , " #b58900" , " #586e75" , " #dc322f" , " #2aa198" ,
103+ " #93a1a1" , " #268bd2" , " #859900" ),
104+ " gruvbox" : Theme(" #fbf1c7" , " #282828" , " #b57614" , " #a89984" , " #9d0006" , " #427b58" ,
105+ " #504945" , " #076678" , " #79740e" ),
106+ " gruvbox-dark" : Theme(" #282828" , " #fbf1c7" , " #d79921" , " #7c6f64" ,
107+ " #cc241d" , " #689d6a" , " #a89984" , " #458588" , " #98971a" )
108+ ];
109+
110+ immutable (Theme)* theme = themeName in themes;
111+ // Default theme
112+ if (theme is null )
113+ theme = &themes[" solarized" ];
114+
115+ return theme;
116+ }
0 commit comments