authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-03 17:39:07-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-03 17:39:07-04:00
logb60f2d0c9fa1d31c817ed39f87cf7619ff742dd3
tree6ae57341ea7eefcabc532178cce6c6d72d5fa1fc
parent692086f898522ecde96742391140bca1212bf4fe
signaturelock-open Commit is signed but in an unrecognized format.

langref: rework the theming and layout

* Instead of the only color scheme being dark, the language reference now has a light theme by default, and respects the user's light/dark preference via prefers-color-scheme media query. Most browsers don't support this yet, so we just have to wait patiently for the future to arrive. closes #2172. * Instead of a side bar index, the index is inline with the rest of the content. This is simpler and more friendly to all user agents, and means we don't need the media query for mobile devices. It also makes back-references work, so now headers link to the table of contents and the table of contents links to headers.

2 files changed, 97 insertions(+), 56 deletions(-)

doc/docgen.zig+14-6
......@@ -385,7 +385,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
385385 last_action = Action.Open;
386386 }
387387 try toc.writeByteNTimes(' ', 4 + header_stack_size * 4);
388 try toc.print("<li><a href=\"#{}\">{}</a>", urlized, content);
388 try toc.print("<li><a id=\"toc-{}\" href=\"#{}\">{}</a>", urlized, urlized, content);
389389 } else if (mem.eql(u8, tag_name, "header_close")) {
390390 if (header_stack_size == 0) {
391391 return parseError(tokenizer, tag_token, "unbalanced close header");
......@@ -706,10 +706,10 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
706706}
707707
708708const builtin_types = [][]const u8{
709 "f16", "f32", "f64", "f128", "c_longdouble", "c_short",
710 "c_ushort", "c_int", "c_uint", "c_long", "c_ulong", "c_longlong",
711 "c_ulonglong", "c_char", "c_void", "void", "bool", "isize",
712 "usize", "noreturn", "type", "anyerror", "comptime_int", "comptime_float",
709 "f16", "f32", "f64", "f128", "c_longdouble", "c_short",
710 "c_ushort", "c_int", "c_uint", "c_long", "c_ulong", "c_longlong",
711 "c_ulonglong", "c_char", "c_void", "void", "bool", "isize",
712 "usize", "noreturn", "type", "anyerror", "comptime_int", "comptime_float",
713713};
714714
715715fn isType(name: []const u8) bool {
......@@ -965,7 +965,15 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
965965 try out.write("</pre>");
966966 },
967967 Node.HeaderOpen => |info| {
968 try out.print("<h{} id=\"{}\"><a href=\"#{}\">{}</a></h{}>\n", info.n, info.url, info.url, info.name, info.n);
968 try out.print(
969 "<h{} id=\"{}\"><a href=\"#toc-{}\">{}</a><a class=\"hdr\" href=\"#{}\">¶</a></h{}>\n",
970 info.n,
971 info.url,
972 info.url,
973 info.name,
974 info.url,
975 info.n,
976 );
969977 },
970978 Node.SeeAlso => |items| {
971979 try out.write("<p>See also:</p><ul>\n");
doc/langref.html.in+83-50
......@@ -6,12 +6,9 @@
66 <title>Documentation - The Zig Programming Language</title>
77 <style type="text/css">
88 body{
9 background-color:#111;
10 color: #bbb;
119 font-family: system-ui, -apple-system, Roboto, "Segoe UI", sans-serif;
1210 }
1311 a {
14 color: #88f;
1512 text-decoration: none;
1613 }
1714 table, th, td {
......@@ -39,17 +36,15 @@
3936 .file {
4037 text-decoration: underline;
4138 }
42 code {
39 pre,code {
4340 font-size: 12pt;
4441 }
4542 pre > code {
4643 display: block;
4744 overflow: auto;
48
49 overflow-x: auto;
5045 padding: 0.5em;
51 color: #ccc;
52 background: #222;
46 color: #333;
47 background: #f8f8f8;
5348 }
5449 .table-wrapper {
5550 width: 100%;
......@@ -57,76 +52,109 @@
5752 }
5853
5954 .tok-kw {
60 color: #eee;
55 color: #333;
6156 font-weight: bold;
6257 }
6358 .tok-str {
64 color: #2e5;
59 color: #d14;
6560 }
6661 .tok-builtin {
67 color: #ff894c;
62 color: #0086b3;
6863 }
6964 .tok-comment {
70 color: #aa7;
65 color: #777;
7166 font-style: italic;
7267 }
7368 .tok-fn {
74 color: #e33;
69 color: #900;
7570 font-weight: bold;
7671 }
7772 .tok-null {
78 color: #ff8080;
73 color: #008080;
7974 }
8075 .tok-number {
81 color: #ff8080;
76 color: #008080;
8277 }
8378 .tok-type {
84 color: #68f;
79 color: #458;
8580 font-weight: bold;
8681 }
8782
88 /* Desktop */
89 @media screen and (min-width: 56.25em) {
90 #nav {
91 width: 20em;
92 height: 100%;
93 position: fixed;
94 overflow-y: scroll;
95 left: 0;
96 top: 0;
97 padding-left: 1em;
98 }
99 #contents {
100 max-width: 60em;
101 padding-left: 22em;
102 padding: 1em;
103 padding-left: 24em;
104 }
105 }
106 /* Mobile */
107 @media screen and (max-width: 56.25em) {
108 body, code {
109 font-size: small;
110 }
111 #nav {
112 border-bottom: 1px solid grey;
113 }
83 #contents {
84 max-width: 60em;
85 margin: auto;
11486 }
87
11588 h1 a, h2 a, h3 a, h4 a, h5 a {
11689 text-decoration: none;
117 color: #aaa;
90 color: #333;
11891 }
119 #nav a {
120 color: #aaa;
121 text-decoration: none;
92
93 a.hdr {
94 visibility: hidden;
95 }
96 h1:hover > a.hdr, h2:hover > a.hdr, h3:hover > a.hdr, h4:hover > a.hdr, h5:hover > a.hdr {
97 visibility: visible;
98 }
99
100 @media (prefers-color-scheme: dark) {
101 body{
102 background-color:#111;
103 color: #bbb;
104 }
105 a {
106 color: #88f;
107 }
108 table, th, td {
109 border-color: grey;
110 }
111 .t2_0 {
112 color: grey;
113 }
114 .t31_1 {
115 color: red;
116 }
117 .t32_1 {
118 color: green;
119 }
120 .t36_1 {
121 color: #0086b3;
122 }
123 pre > code {
124 color: #ccc;
125 background: #222;
126 }
127 .tok-kw {
128 color: #eee;
129 }
130 .tok-str {
131 color: #2e5;
132 }
133 .tok-builtin {
134 color: #ff894c;
135 }
136 .tok-comment {
137 color: #aa7;
138 }
139 .tok-fn {
140 color: #e33;
141 }
142 .tok-null {
143 color: #ff8080;
144 }
145 .tok-number {
146 color: #ff8080;
147 }
148 .tok-type {
149 color: #68f;
150 }
151 h1 a, h2 a, h3 a, h4 a, h5 a {
152 color: #aaa;
153 }
122154 }
123155 </style>
124156 </head>
125157 <body>
126 <div id="nav">
127 <h3>Index</h3>
128 {#nav#}
129 </div>
130158 <div id="contents">
131159 {#header_open|Introduction#}
132160 <p>
......@@ -152,6 +180,11 @@
152180 This HTML document depends on no external files, so you can use it offline.
153181 </p>
154182 {#header_close#}
183
184 {#header_open|Index#}
185 {#nav#}
186 {#header_close#}
187
155188 {#header_open|Hello World#}
156189
157190 {#code_begin|exe|hello#}