From ea1bca05c7c43fb6b1c353d55db7b9ccf3018c14 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 8 Aug 2025 14:30:41 +0200 Subject: [PATCH 1/5] fix no-script default value --- src/main.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index cb99d227..c89fec20 100644 --- a/src/main.zig +++ b/src/main.zig @@ -442,7 +442,7 @@ fn parseFetchArgs( args: *std.process.ArgIterator, ) !Command.Fetch { var dump: bool = false; - var noscript: bool = true; + var noscript: bool = false; var url: ?[]const u8 = null; var common: Command.Common = .{}; From 3d0928a449b1c8a71182ab2342c3fd55040393d3 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 8 Aug 2025 15:18:11 +0200 Subject: [PATCH 2/5] add a --with_base option to fetch with_base option adds a tag to the dump for better offline preview. --- src/browser/dump.zig | 9 +++++++++ src/main.zig | 22 ++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/browser/dump.zig b/src/browser/dump.zig index 68dc6086..2513dae5 100644 --- a/src/browser/dump.zig +++ b/src/browser/dump.zig @@ -23,6 +23,7 @@ const Walker = @import("dom/walker.zig").WalkerChildren; pub const Opts = struct { exclude_scripts: bool = false, + include_base: ?[]const u8 = null, }; // writer must be a std.io.Writer @@ -91,6 +92,14 @@ pub fn writeNode(node: *parser.Node, opts: Opts, writer: anytype) anyerror!void // void elements can't have any content. if (try isVoid(parser.nodeToElement(node))) return; + // If we wrote the
and we want to include a , add it + // now. + if (opts.include_base != null and tag_type == .head) { + try writer.writeAll(""); + } + if (tag_type == .script) { try writer.writeAll(try parser.nodeTextContent(node) orelse ""); } else { diff --git a/src/main.zig b/src/main.zig index c89fec20..70dda469 100644 --- a/src/main.zig +++ b/src/main.zig @@ -134,7 +134,10 @@ fn run(alloc: Allocator) !void { // dump if (opts.dump) { - try page.dump(.{ .exclude_scripts = opts.noscript }, std.io.getStdOut()); + try page.dump(.{ + .exclude_scripts = opts.noscript, + .include_base = if (opts.withbase) page.url.raw else null, + }, std.io.getStdOut()); } }, else => unreachable, @@ -213,6 +216,7 @@ const Command = struct { dump: bool = false, common: Common, noscript: bool = false, + withbase: bool = false, }; const Common = struct { @@ -277,6 +281,7 @@ const Command = struct { \\--dump Dumps document to stdout. \\ Defaults to false. \\--noscript Exclude