Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions doc/docgen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,7 @@ pub fn main() !void {
var toc = try genToc(allocator, &tokenizer);

try os.makePath(allocator, tmp_dir_name);
defer {
// TODO issue #709
// disabled to pass CI tests, but obviously we want to implement this
// and then remove this workaround
if (builtin.os != builtin.Os.windows) {
os.deleteTree(allocator, tmp_dir_name) catch {};
}
}
defer os.deleteTree(allocator, tmp_dir_name) catch {};
try genHtml(allocator, &tokenizer, &toc, &buffered_out_stream.stream, zig_exe);
try buffered_out_stream.flush();
}
Expand Down Expand Up @@ -300,6 +293,7 @@ const Link = struct {
const Node = union(enum) {
Content: []const u8,
Nav,
Builtin,
HeaderOpen: HeaderOpen,
SeeAlso: []const SeeAlsoItem,
Code: Code,
Expand Down Expand Up @@ -356,6 +350,9 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
_ = try eatToken(tokenizer, Token.Id.BracketClose);

try nodes.append(Node.Nav);
} else if (mem.eql(u8, tag_name, "builtin")) {
_ = try eatToken(tokenizer, Token.Id.BracketClose);
try nodes.append(Node.Builtin);
} else if (mem.eql(u8, tag_name, "header_open")) {
_ = try eatToken(tokenizer, Token.Id.Separator);
const content_token = try eatToken(tokenizer, Token.Id.TagContent);
Expand Down Expand Up @@ -690,6 +687,9 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {

fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var, zig_exe: []const u8) !void {
var code_progress_index: usize = 0;

const builtin_code = try escapeHtml(allocator, try getBuiltinCode(allocator, zig_exe));

for (toc.nodes) |node| {
switch (node) {
Node.Content => |data| {
Expand All @@ -704,6 +704,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
Node.Nav => {
try out.write(toc.toc);
},
Node.Builtin => {
try out.print("<pre><code class=\"zig\">{}</code></pre>", builtin_code);
},
Node.HeaderOpen => |info| {
try out.print("<h{} id=\"{}\">{}</h{}>\n", info.n, info.url, info.name, info.n);
},
Expand Down Expand Up @@ -1060,3 +1063,11 @@ fn exec(allocator: *mem.Allocator, args: []const []const u8) !os.ChildProcess.Ex
}
return result;
}

fn getBuiltinCode(allocator: *mem.Allocator, zig_exe: []const u8) ![]const u8 {
const result = try exec(allocator, []const []const u8{
zig_exe,
"builtin",
});
return result.stdout;
}
Loading