Walk document for doctype

This commit is contained in:
Karl Seguin
2026-01-10 08:05:03 +08:00
parent 516a86e33f
commit 6917aeb47b
2 changed files with 16 additions and 1 deletions

View File

@@ -491,7 +491,13 @@ pub fn elementsFromPoint(self: *Document, x: f64, y: f64, page: *Page) ![]const
return result.items; return result.items;
} }
pub fn getDocType(_: *const Document) ?*DocumentType { pub fn getDocType(self: *Document) ?*Node {
var tw = @import("TreeWalker.zig").Full.init(self.asNode(), .{});
while (tw.next()) |node| {
if (node._type == .document_type) {
return node;
}
}
return null; return null;
} }

View File

@@ -215,6 +215,15 @@ pub fn getDocType(self: *HTMLDocument, page: *Page) !*DocumentType {
if (self._document_type) |dt| { if (self._document_type) |dt| {
return dt; return dt;
} }
var tw = @import("TreeWalker.zig").Full.init(self.asNode(), .{});
while (tw.next()) |node| {
if (node._type == .document_type) {
self._document_type = node.as(DocumentType);
return self._document_type.?;
}
}
self._document_type = try page._factory.node(DocumentType{ self._document_type = try page._factory.node(DocumentType{
._proto = undefined, ._proto = undefined,
._name = "html", ._name = "html",