@@ -11,8 +11,10 @@ const collections = @import("collections.zig");
1111pub const CData = @import ("CData.zig" );
1212pub const Element = @import ("Element.zig" );
1313pub const Document = @import ("Document.zig" );
14+ pub const HTMLDocument = @import ("HTMLDocument.zig" );
1415pub const Children = @import ("children.zig" ).Children ;
1516pub const DocumentFragment = @import ("DocumentFragment.zig" );
17+ pub const DocumentType = @import ("DocumentType.zig" );
1618
1719const Allocator = std .mem .Allocator ;
1820const LinkedList = std .DoublyLinkedList ;
@@ -29,6 +31,7 @@ pub const Type = union(enum) {
2931 cdata : * CData ,
3032 element : * Element ,
3133 document : * Document ,
34+ document_type : * DocumentType ,
3235 attribute : * Element.Attribute ,
3336 document_fragment : * DocumentFragment ,
3437};
@@ -76,6 +79,11 @@ pub fn is(self: *Node, comptime T: type) ?*T {
7679 return doc .is (T );
7780 }
7881 },
82+ .document_type = > | dt | {
83+ if (T == DocumentType ) {
84+ return dt ;
85+ }
86+ },
7987 .document_fragment = > | doc | {
8088 if (T == DocumentFragment ) {
8189 return doc ;
@@ -145,6 +153,7 @@ pub fn getTextContent(self: *Node, writer: *std.Io.Writer) error{WriteFailed}!vo
145153 .element = > | el | return el .getInnerText (writer ),
146154 .cdata = > | c | try writer .writeAll (c .getData ()),
147155 .document = > {},
156+ .document_type = > {},
148157 .document_fragment = > {},
149158 .attribute = > | attr | try writer .writeAll (attr ._value ),
150159 }
@@ -163,6 +172,7 @@ pub fn setTextContent(self: *Node, data: []const u8, page: *Page) !void {
163172 .element = > | el | return el .replaceChildren (&.{.{ .text = data }}, page ),
164173 .cdata = > | c | c ._data = try page .arena .dupe (u8 , data ),
165174 .document = > {},
175+ .document_type = > {},
166176 .document_fragment = > {},
167177 .attribute = > | attr | return attr .setValue (data , page ),
168178 }
@@ -176,6 +186,7 @@ pub fn getNodeName(self: *const Node, page: *Page) ![]const u8 {
176186 .comment = > "#comment" ,
177187 },
178188 .document = > "#document" ,
189+ .document_type = > | dt | dt .getName (),
179190 .document_fragment = > "#document-fragment" ,
180191 .attribute = > | attr | attr ._name ,
181192 };
@@ -190,6 +201,7 @@ pub fn nodeType(self: *const Node) u8 {
190201 .comment = > 8 ,
191202 },
192203 .document = > 9 ,
204+ .document_type = > 10 ,
193205 .document_fragment = > 11 ,
194206 };
195207}
@@ -333,6 +345,7 @@ pub fn getNodeValue(self: *const Node) ?[]const u8 {
333345 .attribute = > | attr | attr ._value ,
334346 .element = > null ,
335347 .document = > null ,
348+ .document_type = > null ,
336349 .document_fragment = > null ,
337350 };
338351}
@@ -343,18 +356,19 @@ pub fn setNodeValue(self: *const Node, value: ?[]const u8, page: *Page) !void {
343356 .attribute = > | attr | try attr .setValue (value , page ),
344357 .element = > {},
345358 .document = > {},
359+ .document_type = > {},
346360 .document_fragment = > {},
347361 }
348362}
349363
350364pub fn format (self : * Node , writer : * std.Io.Writer ) ! void {
351365 // // If you need extra debugging:
352366 // return @import("../dump.zig").deep(self, .{}, writer);
353-
354367 return switch (self ._type ) {
355368 .cdata = > | cd | cd .format (writer ),
356369 .element = > | el | writer .print ("{f}" , .{el }),
357370 .document = > writer .writeAll ("<document>" ),
371+ .document_type = > writer .writeAll ("<doctype>" ),
358372 .document_fragment = > writer .writeAll ("<document_fragment>" ),
359373 .attribute = > | attr | writer .print ("{f}" , .{attr }),
360374 };
@@ -380,8 +394,7 @@ pub fn className(self: *const Node) []const u8 {
380394
381395pub fn normalize (self : * Node , page : * Page ) ! void {
382396 var buffer : std .ArrayListUnmanaged (u8 ) = .empty ;
383- const arena = page .call_arena ;
384- return self ._normalize (arena , & buffer , page );
397+ return self ._normalize (page .call_arena , & buffer , page );
385398}
386399
387400pub fn cloneNode (self : * Node , deep_ : ? bool , page : * Page ) error { OutOfMemory , StringTooLarge , NotSupported , NotImplemented }! * Node {
@@ -396,6 +409,7 @@ pub fn cloneNode(self: *Node, deep_: ?bool, page: *Page) error{ OutOfMemory, Str
396409 },
397410 .element = > | el | return el .cloneElement (deep , page ),
398411 .document = > return error .NotSupported ,
412+ .document_type = > return error .NotSupported ,
399413 .document_fragment = > return error .NotImplemented ,
400414 .attribute = > return error .NotSupported ,
401415 }
@@ -612,6 +626,7 @@ pub const JsApi = struct {
612626 .cdata = > | cdata | return cdata .getData (),
613627 .attribute = > | attr | return attr ._value ,
614628 .document = > return null ,
629+ .document_type = > return null ,
615630 .document_fragment = > return null ,
616631 }
617632 }
0 commit comments