From 446b4dc46113ca1f1919d73252b15fe2440558a4 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Wed, 21 Jan 2026 14:15:11 +0800 Subject: [PATCH] On dump, use the HTMLDocument's doctype if available We currently force-write a simple HTML doctype for HTMLDocument. But if the document already has a doctype, that results in us writing the forced one then writing the correct one. This adds a check and only force-writes a doctype if the first child of the document isn't a document_type node. --- src/browser/dump.zig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/browser/dump.zig b/src/browser/dump.zig index bc4d5431..ab863eef 100644 --- a/src/browser/dump.zig +++ b/src/browser/dump.zig @@ -51,7 +51,18 @@ pub const Opts = struct { pub fn root(doc: *Node.Document, opts: RootOpts, writer: *std.Io.Writer, page: *Page) !void { if (doc.is(Node.Document.HTMLDocument)) |html_doc| { - try writer.writeAll(""); + blk: { + // Ideally we just render the doctype which is part of the document + if (doc.asNode().firstChild()) |first| { + if (first._type == .document_type) { + break :blk; + } + } + // But if the doc has no child, or the first child isn't a doctype + // well force it. + try writer.writeAll(""); + } + if (opts.with_base) { const parent = if (html_doc.getHead()) |head| head.asNode() else doc.asNode(); const base = try doc.createElement("base", null, page);