╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ docgen.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
988 if (escape) { 989 try writeEscaped(out, line); 990 } else { 991 try out.writeAll(line); 992 } 993 try out.writeAll("</kbd>" ++ "\n"); 994 cmd_cont = false; 995 } else { 996 if (escape) { 997 try writeEscaped(out, line); 998 } else { 999 try out.writeAll(line); 1000 } 1001 try out.writeAll("\n"); 1002 } 1003 } 1004 1005 try out.writeAll("</samp></pre></figure>"); 1006 } 1007 1008 fn genHtml( 1009 allocator: Allocator, 1010 io: Io, 1011 tokenizer: *Tokenizer, 1012 toc: *Toc, 1013 code_dir: Path, 1014 grammar: []const u8, 1015 out: *Writer, 1016 ) !void { 1017 for (toc.nodes) |node| { 1018 switch (node) { 1019 .Content => |data| { 1020 try out.writeAll(data); 1021 }, 1022 .Link => |info| { 1023 if (!toc.urls.contains(info.url)) { 1024 return parseError(tokenizer, info.token, "url not found: {s}", .{info.url}); 1025 } 1026 try out.print("<a href=\"#{s}\">{s}</a>", .{ info.url, info.name }); 1027 }, 1028 .Nav => { 1029 try out.writeAll(toc.toc); 1030 }, 1031 .Builtin => |tok| { 1032 try out.writeAll("<figure><figcaption class=\"zig-cap\"><cite>@import(\"builtin\")</cite></figcaption><pre>"); 1033 const builtin_code = @embedFile("builtin"); // 😎 1034 try tokenizeAndPrintRaw(allocator, tokenizer, out, tok, builtin_code); 1035 try out.writeAll("</pre></figure>"); 1036 }, 1037 .HeaderOpen => |info| { 1038 try out.print( 1039 "<h{d} id=\"{s}\"><a href=\"#toc-{s}\">{s}</a> <a class=\"hdr\" href=\"#{s}\">§</a></h{d}>\n", 1040 .{ info.n, info.url, info.url, info.name, info.url, info.n }, 1041 ); 1042 }, 1043 .SeeAlso => |items| { 1044 try out.writeAll("<p>See also:</p><ul>\n"); 1045 for (items) |item| { 1046 const url = try urlize(allocator, item.name); 1047 if (!toc.urls.contains(url)) { 1048 return parseError(tokenizer, item.token, "url not found: {s}", .{url}); 1049 } 1050 try out.print("<li><a href=\"#{s}\">{s}</a></li>\n", .{ url, item.name }); 1051 } 1052 try out.writeAll("</ul>\n"); 1053 }, 1054 .InlineSyntax => |content_tok| { 1055 try tokenizeAndPrint(allocator, tokenizer, out, content_tok); 1056 }, 1057 .Shell => |content_tok| { 1058 const raw_shell_content = tokenizer.buffer[content_tok.start..content_tok.end]; 1059 try printShell(out, raw_shell_content, true); 1060 }, 1061 .SyntaxBlock => |syntax_block| { 1062 try printSourceBlock(allocator, tokenizer, out, syntax_block, null); 1063 }, 1064 .Code => |code| { 1065 const out_basename = try std.fmt.allocPrint(allocator, "{s}.out", .{ 1066 Dir.path.stem(code.name), 1067 }); 1068 defer allocator.free(out_basename); 1069 1070 const out_path: Path = .{ 1071 .root_dir = code_dir.root_dir, 1072 .sub_path = out_basename, 1073 }; 1074 1075 const contents = out_path.root_dir.handle.readFileAlloc(io, out_path.sub_path, allocator, .unlimited) catch |err| { 1076 return parseError(tokenizer, code.token, "failed opening {f}: {t}", .{ out_path, err }); 1077 }; 1078 defer allocator.free(contents); 1079 1080 try out.writeAll(contents); 1081 }, 1082 .Grammar => { 1083 try printSourceBlock(allocator, tokenizer, out, .{ 1084 .source_type = .peg, 1085 .name = "grammar.peg", 1086 .source_token = undefined, 1087 }, grammar); 1088 }, 1089 } 1090 } 1091 } 1092