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 @@...@@ -200,24 +200,9 @@
200 visibility: visible;200 visibility: visible;
201 }201 }
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 }
215 th pre code {203 th pre code {
216 background: none;204 background: none;
217 }205 }
218 th .line:before {
219 display: none;
220 }
221206
222 @media (prefers-color-scheme: dark) {207 @media (prefers-color-scheme: dark) {
223 body{208 body{
tools/docgen.zig+6-28
...@@ -947,19 +947,8 @@ fn isType(name: []const u8) bool {...@@ -947,19 +947,8 @@ fn isType(name: []const u8) bool {
947 return false;947 return false;
948}948}
949949
950const start_line = "<span class=\"line\">";
951const end_line = "</span>";
952
953fn writeEscapedLines(out: anytype, text: []const u8) !void {950fn writeEscapedLines(out: anytype, text: []const u8) !void {
954 for (text) |char| {951 return writeEscaped(out, text);
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 }
963}952}
964953
965fn tokenizeAndPrintRaw(954fn tokenizeAndPrintRaw(
...@@ -972,7 +961,7 @@ fn tokenizeAndPrintRaw(...@@ -972,7 +961,7 @@ fn tokenizeAndPrintRaw(
972 const src_non_terminated = mem.trim(u8, raw_src, " \r\n");961 const src_non_terminated = mem.trim(u8, raw_src, " \r\n");
973 const src = try allocator.dupeZ(u8, src_non_terminated);962 const src = try allocator.dupeZ(u8, src_non_terminated);
974963
975 try out.writeAll("<code>" ++ start_line);964 try out.writeAll("<code>");
976 var tokenizer = std.zig.Tokenizer.init(src);965 var tokenizer = std.zig.Tokenizer.init(src);
977 var index: usize = 0;966 var index: usize = 0;
978 var next_tok_is_fn = false;967 var next_tok_is_fn = false;
...@@ -1062,6 +1051,7 @@ fn tokenizeAndPrintRaw(...@@ -1062,6 +1051,7 @@ fn tokenizeAndPrintRaw(
1062 },1051 },
10631052
1064 .string_literal,1053 .string_literal,
1054 .multiline_string_literal_line,
1065 .char_literal,1055 .char_literal,
1066 => {1056 => {
1067 try out.writeAll("<span class=\"tok-str\">");1057 try out.writeAll("<span class=\"tok-str\">");
...@@ -1069,18 +1059,6 @@ fn tokenizeAndPrintRaw(...@@ -1069,18 +1059,6 @@ fn tokenizeAndPrintRaw(
1069 try out.writeAll("</span>");1059 try out.writeAll("</span>");
1070 },1060 },
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
1084 .builtin => {1062 .builtin => {
1085 try out.writeAll("<span class=\"tok-builtin\">");1063 try out.writeAll("<span class=\"tok-builtin\">");
1086 try writeEscaped(out, src[token.loc.start..token.loc.end]);1064 try writeEscaped(out, src[token.loc.start..token.loc.end]);
...@@ -1211,7 +1189,7 @@ fn tokenizeAndPrintRaw(...@@ -1211,7 +1189,7 @@ fn tokenizeAndPrintRaw(
1211 }1189 }
1212 index = token.loc.end;1190 index = token.loc.end;
1213 }1191 }
1214 try out.writeAll(end_line ++ "</code>");1192 try out.writeAll("</code>");
1215}1193}
12161194
1217fn tokenizeAndPrint(1195fn tokenizeAndPrint(
...@@ -1234,9 +1212,9 @@ fn printSourceBlock(allocator: Allocator, docgen_tokenizer: *Tokenizer, out: any...@@ -1234,9 +1212,9 @@ fn printSourceBlock(allocator: Allocator, docgen_tokenizer: *Tokenizer, out: any
1234 const raw_source = docgen_tokenizer.buffer[syntax_block.source_token.start..syntax_block.source_token.end];1212 const raw_source = docgen_tokenizer.buffer[syntax_block.source_token.start..syntax_block.source_token.end];
1235 const trimmed_raw_source = mem.trim(u8, raw_source, " \r\n");1213 const trimmed_raw_source = mem.trim(u8, raw_source, " \r\n");
12361214
1237 try out.writeAll("<code>" ++ start_line);1215 try out.writeAll("<code>");
1238 try writeEscapedLines(out, trimmed_raw_source);1216 try writeEscapedLines(out, trimmed_raw_source);
1239 try out.writeAll(end_line ++ "</code>");1217 try out.writeAll("</code>");
1240 },1218 },
1241 }1219 }
1242 try out.writeAll("</pre></figure>");1220 try out.writeAll("</pre></figure>");