Skip to content

Commit 28b130e

Browse files
Merge pull request #23 from matthijsgroen/theming
Start on dark / light theme
2 parents d60f934 + 0884737 commit 28b130e

File tree

1 file changed

+104
-18
lines changed

1 file changed

+104
-18
lines changed

src/report-html-template.js

Lines changed: 104 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,30 @@ ${body}
2323
</html>
2424
`;
2525

26+
const currentDate = () => {
27+
const date = new Date();
28+
const pad = number => (number < 10 ? "0" + number : number);
29+
30+
return `${date.getUTCFullYear()}-${pad(date.getUTCMonth() + 1)}-${pad(
31+
date.getUTCDate()
32+
)}T${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}`;
33+
};
34+
2635
const documentContent = ({ title, contents, toc, singleRoot }) =>
27-
`<header>
36+
`
37+
<script type="text/javascript">
38+
const htmlTag = document.getElementsByTagName("html")[0];
39+
const options = (document.location.search || "")
40+
.slice(1)
41+
.split("&")
42+
.map(kv => kv.split("="))
43+
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
44+
45+
if (options["theme"]) {
46+
htmlTag.classList.add("theme-" + options["theme"]);
47+
}
48+
</script>
49+
<header>
2850
<h1>${title}</h1>
2951
<button type="button"></button>
3052
</header>
@@ -46,14 +68,17 @@ const documentContent = ({ title, contents, toc, singleRoot }) =>
4668
<article>
4769
${contents}
4870
</article>
71+
<footer>
72+
<p>Date: ${currentDate()} - <a href="?theme=dark">Dark</a> - <a href="?theme=light">Light</a></p>
73+
</footer>
4974
</main>
5075
<script type="text/javascript">
5176
document.querySelector("header button").addEventListener("click", function() {
5277
document.getElementsByTagName("html")[0].classList.toggle("menu-open");
5378
});
5479
document.querySelector("nav").addEventListener("click", function(event) {
5580
if (event.target.tagName !== "A") return;
56-
document.getElementsByTagName("html")[0].classList.remove("menu-open");
81+
htmlTag.classList.remove("menu-open");
5782
});
5883
</script>
5984
`;
@@ -72,7 +97,48 @@ html {
7297
--subtleText: #777;
7398
--highlightText: hotpink;
7499
--itemHeadingBackground: #eee;
100+
--background: white;
101+
--borderColor: #ccc;
102+
--textColor: #111;
103+
75104
--diagramBackground: #f8f8f8;
105+
--diagramLines: black;
106+
--diagramText: black;
107+
--terminalLines: black;
108+
--terminalFill: #feffdf;
109+
--nonTerminalLines: black;
110+
--nonTerminalFill: #feffdf;
111+
--specialSequenceLines: black;
112+
--specialSequenceFill: #ffe79a;
113+
114+
--ebnfCodeBackground: #e8e8e8;
115+
--ebnfIdentifier: #ef5a5a;
116+
--ebnfTerminal: #ffa952;
117+
--ebnfBaseColor: #777;
118+
}
119+
120+
.theme-dark {
121+
--subtleText: #777;
122+
--highlightText: hotpink;
123+
--itemHeadingBackground: #444;
124+
--background: #333;
125+
--borderColor: lightblue;
126+
--textColor: #ddd;
127+
128+
--diagramBackground: #222;
129+
--diagramLines: lightblue;
130+
--diagramText: #a7d129;
131+
--terminalLines: #a7d129;
132+
--terminalFill: #3e432e;
133+
--nonTerminalLines: #a7d129;
134+
--nonTerminalFill: #3e432e;
135+
--specialSequenceLines: #a7d129;
136+
--specialSequenceFill: #616f39;
137+
138+
--ebnfCodeBackground: #3e432e;
139+
--ebnfIdentifier: lightblue;
140+
--ebnfTerminal: #a7d129;
141+
--ebnfBaseColor: #ddd;
76142
}
77143
78144
html {
@@ -82,6 +148,8 @@ html {
82148
html, body {
83149
margin: 0;
84150
padding: 0;
151+
background: var(--background);
152+
color: var(--textColor);
85153
}
86154
87155
a {
@@ -97,7 +165,7 @@ a:active, a:focus, a:hover {
97165
}
98166
99167
header {
100-
border-bottom: 1px solid #ccc;
168+
border-bottom: 1px solid var(--borderColor);
101169
padding: 1rem;
102170
}
103171
@@ -106,18 +174,17 @@ header button {
106174
}
107175
108176
main {
109-
display: flex;
110177
overflow: hidden;
111178
margin-left: 300px;
112179
}
113180
114181
nav {
115182
position: sticky;
116183
top: 0;
117-
height: 100vh;
184+
max-height: 100vh;
118185
padding: 1rem 2rem 1rem 1rem;
119186
z-index: 5;
120-
background: white;
187+
background: var(--background);
121188
width: 300px;
122189
float: left;
123190
overflow: auto;
@@ -143,7 +210,13 @@ article {
143210
width: 100%;
144211
overflow: hidden;
145212
padding: 1rem 2rem;
146-
border-left: 1px solid #ccc;
213+
border-left: 1px solid var(--borderColor);
214+
}
215+
216+
article + footer {
217+
padding: 1rem 2rem;
218+
border-left: 1px solid var(--borderColor);
219+
background: var(--itemHeadingBackground);
147220
}
148221
149222
code {
@@ -183,6 +256,10 @@ dfn {
183256
184257
/* Responsiveness */
185258
@media (max-width: 640px) {
259+
body {
260+
overflow-x: hidden;
261+
}
262+
186263
header {
187264
padding: 0.5rem 1rem;
188265
display: flex;
@@ -217,18 +294,20 @@ dfn {
217294
display: block;
218295
pointer-events: none;
219296
opacity: 0;
220-
transition: opacity 0.2s;
297+
transition: opacity 0.2s, transform 0.2s;
221298
position: absolute;
222299
top: 0;
223300
right: 0;
301+
transform: translateX(300px);
224302
padding-top: 3rem;
225-
background: white;
303+
background: var(--background);
226304
box-shadow: 0 0 0 1000000rem rgba(0, 0, 0, 0.35);
227305
}
228306
229307
.menu-open nav {
230308
pointer-events: auto;
231309
opacity: 1;
310+
transform: translateX(0px);
232311
}
233312
234313
nav a {
@@ -240,23 +319,27 @@ dfn {
240319
border-left: 0;
241320
padding: 1rem;
242321
}
322+
article + footer {
323+
padding: 1rem;
324+
border-left: 0;
325+
}
243326
}
244327
245328
/* EBNF text representation styling */
246329
code.ebnf {
247330
padding: 1em;
248-
background: rgb(255, 246, 209);
331+
background: var(--ebnfCodeBackground);
249332
font-weight: bold;
250-
color: #777;
333+
color: var(--ebnfBaseColor);
251334
white-space: pre-wrap;
252335
display: inline-block;
253336
width: 100%;
254337
}
255338
.ebnf-identifier {
256-
color: #990099;
339+
color: var(--ebnfIdentifier);
257340
}
258341
.ebnf-terminal {
259-
color: #009900;
342+
color: var(--ebnfTerminal);
260343
}
261344
.ebnf-non-terminal {
262345
font-weight: normal;
@@ -273,12 +356,13 @@ svg.railroad-diagram {
273356
}
274357
svg.railroad-diagram path {
275358
stroke-width: 3;
276-
stroke: black;
359+
stroke: var(--diagramLines);
277360
fill: rgba(0,0,0,0);
278361
}
279362
svg.railroad-diagram text {
280363
font: bold 14px monospace;
281364
text-anchor: middle;
365+
fill: var(--diagramText);
282366
}
283367
svg.railroad-diagram text.diagram-text {
284368
font-size: 12px;
@@ -296,20 +380,22 @@ svg.railroad-diagram g.non-terminal text {
296380
/*font-style: italic;*/
297381
}
298382
svg.railroad-diagram g.special-sequence rect {
299-
fill: #FFDB4D;
383+
fill: var(--specialSequenceFill);
384+
stroke: var(--specialSequenceLines);
300385
}
301386
svg.railroad-diagram g.special-sequence text {
302387
font-style: italic;
303388
}
304389
svg.railroad-diagram rect {
305390
stroke-width: 3;
306-
stroke: black;
307391
}
308392
svg.railroad-diagram g.non-terminal rect {
309-
fill: hsl(120,100%,90%);
393+
fill: var(--nonTerminalFill);
394+
stroke: var(--nonTerminalLines);
310395
}
311396
svg.railroad-diagram g.terminal rect {
312-
fill: hsl(120,100%,90%);
397+
fill: var(--terminalFill);
398+
stroke: var(--terminalLines);
313399
}
314400
svg.railroad-diagram path.diagram-text {
315401
stroke-width: 3;

0 commit comments

Comments
 (0)