@@ -33,7 +33,20 @@ const currentDate = () => {
3333} ;
3434
3535const documentContent = ( { title, contents, toc, singleRoot } ) =>
36- `<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>
3750 <h1>${ title } </h1>
3851 <button type="button"></button>
3952 </header>
@@ -56,32 +69,17 @@ const documentContent = ({ title, contents, toc, singleRoot }) =>
5669 ${ contents }
5770 </article>
5871 <footer>
59- <p>Date: ${ currentDate ( ) } - <a href="# theme/ dark">Dark</a> - <a href="# theme/ light">Light</a></p>
72+ <p>Date: ${ currentDate ( ) } - <a href="? theme= dark">Dark</a> - <a href="? theme= light">Light</a></p>
6073 </footer>
6174 </main>
6275 <script type="text/javascript">
6376 document.querySelector("header button").addEventListener("click", function() {
6477 document.getElementsByTagName("html")[0].classList.toggle("menu-open");
6578 });
66- const htmlTag = document.getElementsByTagName("html")[0];
6779 document.querySelector("nav").addEventListener("click", function(event) {
6880 if (event.target.tagName !== "A") return;
6981 htmlTag.classList.remove("menu-open");
7082 });
71-
72- document.querySelector("main footer").addEventListener("click", function(event) {
73- if (event.target.getAttribute("href").startsWith("#theme/")) {
74- event.preventDefault();
75- if (event.target.getAttribute("href") === "#theme/dark") {
76- htmlTag.classList.remove("theme-light");
77- htmlTag.classList.add("theme-dark");
78- }
79- if (event.target.getAttribute("href") === "#theme/light") {
80- htmlTag.classList.remove("theme-dark");
81- htmlTag.classList.add("theme-light");
82- }
83- }
84- });
8583 </script>
8684` ;
8785
@@ -99,20 +97,48 @@ html {
9997 --subtleText: #777;
10098 --highlightText: hotpink;
10199 --itemHeadingBackground: #eee;
102- --diagramBackground: #f8f8f8;
103100 --background: white;
104101 --borderColor: #ccc;
105102 --textColor: #111;
103+
104+ --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;
106118}
107119
108120.theme-dark {
109121 --subtleText: #777;
110122 --highlightText: hotpink;
111- --itemHeadingBackground: #eee;
112- --diagramBackground: #f8f8f8;
123+ --itemHeadingBackground: #444;
113124 --background: #333;
114125 --borderColor: lightblue;
115126 --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;
116142}
117143
118144html {
@@ -123,7 +149,6 @@ html, body {
123149 margin: 0;
124150 padding: 0;
125151 background: var(--background);
126- overflow-x: hidden;
127152 color: var(--textColor);
128153}
129154
@@ -191,6 +216,7 @@ article {
191216article + footer {
192217 padding: 1rem 2rem;
193218 border-left: 1px solid var(--borderColor);
219+ background: var(--itemHeadingBackground);
194220}
195221
196222code {
@@ -230,6 +256,10 @@ dfn {
230256
231257/* Responsiveness */
232258@media (max-width: 640px) {
259+ body {
260+ overflow-x: hidden;
261+ }
262+
233263 header {
234264 padding: 0.5rem 1rem;
235265 display: flex;
@@ -298,18 +328,18 @@ dfn {
298328/* EBNF text representation styling */
299329code.ebnf {
300330 padding: 1em;
301- background: rgb(255, 246, 209 );
331+ background: var(--ebnfCodeBackground );
302332 font-weight: bold;
303- color: #777 ;
333+ color: var(--ebnfBaseColor) ;
304334 white-space: pre-wrap;
305335 display: inline-block;
306336 width: 100%;
307337}
308338.ebnf-identifier {
309- color: #990099 ;
339+ color: var(--ebnfIdentifier) ;
310340}
311341.ebnf-terminal {
312- color: #009900 ;
342+ color: var(--ebnfTerminal) ;
313343}
314344.ebnf-non-terminal {
315345 font-weight: normal;
@@ -326,12 +356,13 @@ svg.railroad-diagram {
326356}
327357svg.railroad-diagram path {
328358 stroke-width: 3;
329- stroke: black ;
359+ stroke: var(--diagramLines) ;
330360 fill: rgba(0,0,0,0);
331361}
332362svg.railroad-diagram text {
333363 font: bold 14px monospace;
334364 text-anchor: middle;
365+ fill: var(--diagramText);
335366}
336367svg.railroad-diagram text.diagram-text {
337368 font-size: 12px;
@@ -349,20 +380,22 @@ svg.railroad-diagram g.non-terminal text {
349380 /*font-style: italic;*/
350381}
351382svg.railroad-diagram g.special-sequence rect {
352- fill: #FFDB4D;
383+ fill: var(--specialSequenceFill);
384+ stroke: var(--specialSequenceLines);
353385}
354386svg.railroad-diagram g.special-sequence text {
355387 font-style: italic;
356388}
357389svg.railroad-diagram rect {
358390 stroke-width: 3;
359- stroke: black;
360391}
361392svg.railroad-diagram g.non-terminal rect {
362- fill: hsl(120,100%,90%);
393+ fill: var(--nonTerminalFill);
394+ stroke: var(--nonTerminalLines);
363395}
364396svg.railroad-diagram g.terminal rect {
365- fill: hsl(120,100%,90%);
397+ fill: var(--terminalFill);
398+ stroke: var(--terminalLines);
366399}
367400svg.railroad-diagram path.diagram-text {
368401 stroke-width: 3;
0 commit comments