@@ -25,6 +25,7 @@ const Parser = @import("../parser/Parser.zig");
2525
2626const HTMLDocument = @import ("HTMLDocument.zig" );
2727const XMLDocument = @import ("XMLDocument.zig" );
28+ const Document = @import ("Document.zig" );
2829const ProcessingInstruction = @import ("../webapi/cdata/ProcessingInstruction.zig" );
2930
3031const DOMParser = @This ();
@@ -33,26 +34,21 @@ pub fn init() DOMParser {
3334 return .{};
3435}
3536
36- pub const HTMLDocumentOrXMLDocument = union (enum ) {
37- html_document : * HTMLDocument ,
38- xml_document : * XMLDocument ,
39- };
40-
4137pub fn parseFromString (
4238 _ : * const DOMParser ,
4339 html : []const u8 ,
4440 mime_type : []const u8 ,
4541 page : * Page ,
46- ) ! HTMLDocumentOrXMLDocument {
47- const maybe_target_mime = std .meta .stringToEnum (enum {
42+ ) ! * Document {
43+ const target_mime = std .meta .stringToEnum (enum {
4844 @"text/html" ,
4945 @"text/xml" ,
5046 @"application/xml" ,
5147 @"application/xhtml+xml" ,
5248 @"image/svg+xml" ,
53- }, mime_type );
49+ }, mime_type ) orelse return error . NotSupported ;
5450
55- if ( maybe_target_mime ) | target_mime | switch (target_mime ) {
51+ return switch (target_mime ) {
5652 .@"text/html" = > {
5753 // Create a new HTMLDocument
5854 const doc = try page ._factory .document (HTMLDocument {
@@ -72,7 +68,7 @@ pub fn parseFromString(
7268 return pe .err ;
7369 }
7470
75- return .{ . html_document = doc } ;
71+ return doc . asDocument () ;
7672 },
7773 else = > {
7874 // Create a new XMLDocument.
@@ -100,11 +96,9 @@ pub fn parseFromString(
10096 _ = doc_node .removeChild (first_child , page ) catch unreachable ;
10197 }
10298
103- return .{ . xml_document = doc } ;
99+ return doc . asDocument () ;
104100 },
105101 };
106-
107- return error .NotSupported ;
108102}
109103
110104pub const JsApi = struct {
0 commit comments