diff --git a/src/browser/Page.zig b/src/browser/Page.zig index 9bfd17cf..af235a5b 100644 --- a/src/browser/Page.zig +++ b/src/browser/Page.zig @@ -868,7 +868,6 @@ fn notifyNetworkAlmostIdle(self: *Page) void { // called from the parser pub fn appendNew(self: *Page, parent: *Node, child: Node.NodeOrText) !void { - // TODO: should some of this be pushed into appendNode... ? const node = switch (child) { .node => |n| n, .text => |txt| blk: { diff --git a/src/browser/dump.zig b/src/browser/dump.zig index 62807397..adcef586 100644 --- a/src/browser/dump.zig +++ b/src/browser/dump.zig @@ -24,6 +24,7 @@ const Slot = @import("webapi/element/html/Slot.zig"); pub const RootOpts = struct { with_base: bool = false, strip: Opts.Strip = .{}, + shadow: Opts.Shadow = .rendered, }; pub const Opts = struct { @@ -48,10 +49,10 @@ pub const Opts = struct { }; }; -pub fn root(opts: RootOpts, writer: *std.Io.Writer, page: *Page) !void { - const doc = page.document; +pub fn root(doc: *Node.Document, opts: RootOpts, writer: *std.Io.Writer, page: *Page) !void { if (opts.with_base) { if (doc.is(Node.Document.HTMLDocument)) |html_doc| { + try writer.writeAll(""); const parent = if (html_doc.getHead()) |head| head.asNode() else doc.asNode(); const base = try doc.createElement("base", null, page); try base.setAttributeSafe("base", page.url, page); @@ -59,7 +60,7 @@ pub fn root(opts: RootOpts, writer: *std.Io.Writer, page: *Page) !void { } } - return deep(doc.asNode(), .{ .strip = opts.strip }, writer, page); + return deep(doc.asNode(), .{ .strip = opts.strip, .shadow = opts.shadow }, writer, page); } pub fn deep(node: *Node, opts: Opts, writer: *std.Io.Writer, page: *Page) error{WriteFailed}!void { @@ -130,7 +131,29 @@ fn _deep(node: *Node, opts: Opts, comptime force_slot: bool, writer: *std.Io.Wri } }, .document => try children(node, opts, writer, page), - .document_type => {}, + .document_type => |dt| { + try writer.writeAll("\n"); + }, .document_fragment => try children(node, opts, writer, page), .attribute => unreachable, } diff --git a/src/browser/parser/Parser.zig b/src/browser/parser/Parser.zig index 65e25ecd..24991caf 100644 --- a/src/browser/parser/Parser.zig +++ b/src/browser/parser/Parser.zig @@ -219,17 +219,25 @@ fn _createCommentCallback(self: *Parser, str: []const u8) !*anyopaque { } fn appendDoctypeToDocument(ctx: *anyopaque, name: h5e.StringSlice, public_id: h5e.StringSlice, system_id: h5e.StringSlice) callconv(.c) void { - _ = public_id; - _ = system_id; - const self: *Parser = @ptrCast(@alignCast(ctx)); - self._appendDoctypeToDocument(name.slice()) catch |err| { + self._appendDoctypeToDocument(name.slice(), public_id.slice(), system_id.slice()) catch |err| { self.err = .{ .err = err, .source = .append_doctype_to_document }; }; } -fn _appendDoctypeToDocument(self: *Parser, name: []const u8) !void { - _ = self; - _ = name; +fn _appendDoctypeToDocument(self: *Parser, name: []const u8, public_id: []const u8, system_id: []const u8) !void { + const page = self.page; + + // Create the DocumentType node + const DocumentType = @import("../webapi/DocumentType.zig"); + const doctype = try page._factory.node(DocumentType{ + ._proto = undefined, + ._name = try page.dupeString(name), + ._public_id = try page.dupeString(public_id), + ._system_id = try page.dupeString(system_id), + }); + + // Append it to the document + try page.appendNew(self.container.node, .{ .node = doctype.asNode() }); } fn addAttrsIfMissingCallback(ctx: *anyopaque, target_ref: *anyopaque, attributes: h5e.AttributeIterator) callconv(.c) void { diff --git a/src/browser/tests/document/document.html b/src/browser/tests/document/document.html index 8658b9b6..1138c132 100644 --- a/src/browser/tests/document/document.html +++ b/src/browser/tests/document/document.html @@ -8,6 +8,7 @@