authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-21 17:13:59-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-21 20:31:13-07:00
log9be831e15ac28c1e183cebe36e7e1267114efa60
tree80b3535e27454de00bb6247dec3b99cb6ffcb702
parenta054c01f5ceb0575909e9d416320f393514472dc

langref: remove line numbers from code samples

It's unnecessary, more complicated, bloated, and it messes up the table of operators.

2 files changed, 6 insertions(+), 43 deletions(-)

doc/langref.html.in-15
......@@ -200,24 +200,9 @@
200200 visibility: visible;
201201 }
202202
203 pre {
204 counter-reset: line;
205 }
206 pre .line:before {
207 counter-increment: line;
208 content: counter(line);
209 display: inline-block;
210 padding-right: 1em;
211 width: 2em;
212 text-align: right;
213 color: #999;
214 }
215203 th pre code {
216204 background: none;
217205 }
218 th .line:before {
219 display: none;
220 }
221206
222207 @media (prefers-color-scheme: dark) {
223208 body{
tools/docgen.zig+6-28
......@@ -947,19 +947,8 @@ fn isType(name: []const u8) bool {
947947 return false;
948948}
949949
950const start_line = "<span class=\"line\">";
951const end_line = "</span>";
952
953950fn writeEscapedLines(out: anytype, text: []const u8) !void {
954 for (text) |char| {
955 if (char == '\n') {
956 try out.writeAll(end_line);
957 try out.writeAll("\n");
958 try out.writeAll(start_line);
959 } else {
960 try writeEscaped(out, &[_]u8{char});
961 }
962 }
951 return writeEscaped(out, text);
963952}
964953
965954fn tokenizeAndPrintRaw(
......@@ -972,7 +961,7 @@ fn tokenizeAndPrintRaw(
972961 const src_non_terminated = mem.trim(u8, raw_src, " \r\n");
973962 const src = try allocator.dupeZ(u8, src_non_terminated);
974963
975 try out.writeAll("<code>" ++ start_line);
964 try out.writeAll("<code>");
976965 var tokenizer = std.zig.Tokenizer.init(src);
977966 var index: usize = 0;
978967 var next_tok_is_fn = false;
......@@ -1062,6 +1051,7 @@ fn tokenizeAndPrintRaw(
10621051 },
10631052
10641053 .string_literal,
1054 .multiline_string_literal_line,
10651055 .char_literal,
10661056 => {
10671057 try out.writeAll("<span class=\"tok-str\">");
......@@ -1069,18 +1059,6 @@ fn tokenizeAndPrintRaw(
10691059 try out.writeAll("</span>");
10701060 },
10711061
1072 .multiline_string_literal_line => {
1073 if (src[token.loc.end - 1] == '\n') {
1074 try out.writeAll("<span class=\"tok-str\">");
1075 try writeEscaped(out, src[token.loc.start .. token.loc.end - 1]);
1076 try out.writeAll("</span>" ++ end_line ++ "\n" ++ start_line);
1077 } else {
1078 try out.writeAll("<span class=\"tok-str\">");
1079 try writeEscaped(out, src[token.loc.start..token.loc.end]);
1080 try out.writeAll("</span>");
1081 }
1082 },
1083
10841062 .builtin => {
10851063 try out.writeAll("<span class=\"tok-builtin\">");
10861064 try writeEscaped(out, src[token.loc.start..token.loc.end]);
......@@ -1211,7 +1189,7 @@ fn tokenizeAndPrintRaw(
12111189 }
12121190 index = token.loc.end;
12131191 }
1214 try out.writeAll(end_line ++ "</code>");
1192 try out.writeAll("</code>");
12151193}
12161194
12171195fn tokenizeAndPrint(
......@@ -1234,9 +1212,9 @@ fn printSourceBlock(allocator: Allocator, docgen_tokenizer: *Tokenizer, out: any
12341212 const raw_source = docgen_tokenizer.buffer[syntax_block.source_token.start..syntax_block.source_token.end];
12351213 const trimmed_raw_source = mem.trim(u8, raw_source, " \r\n");
12361214
1237 try out.writeAll("<code>" ++ start_line);
1215 try out.writeAll("<code>");
12381216 try writeEscapedLines(out, trimmed_raw_source);
1239 try out.writeAll(end_line ++ "</code>");
1217 try out.writeAll("</code>");
12401218 },
12411219 }
12421220 try out.writeAll("</pre></figure>");