File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -60,14 +60,24 @@ pub const Element = struct {
60
60
61
61
pub fn toInterfaceT (comptime T : type , e : * parser.Element ) ! T {
62
62
const tagname = try parser .elementGetTagName (e ) orelse {
63
- // in case of null tagname, return the element as it.
63
+ // If the owner's document is HTML, assume we have an HTMLElement.
64
+ const doc = try parser .nodeOwnerDocument (parser .elementToNode (e ));
65
+ if (doc != null and ! doc .? .is_html ) {
66
+ return .{ .HTMLElement = @as (* parser .ElementHTML , @ptrCast (e )) };
67
+ }
68
+
64
69
return .{ .Element = e };
65
70
};
66
71
67
72
// TODO SVGElement and MathML are not supported yet.
68
73
69
74
const tag = parser .Tag .fromString (tagname ) catch {
70
- // if the tag is invalid, we don't have an HTMLElement.
75
+ // If the owner's document is HTML, assume we have an HTMLElement.
76
+ const doc = try parser .nodeOwnerDocument (parser .elementToNode (e ));
77
+ if (doc != null and doc .? .is_html ) {
78
+ return .{ .HTMLElement = @as (* parser .ElementHTML , @ptrCast (e )) };
79
+ }
80
+
71
81
return .{ .Element = e };
72
82
};
73
83
Original file line number Diff line number Diff line change @@ -75,7 +75,14 @@ pub const Node = struct {
75
75
.text = > .{ .Text = @as (* parser .Text , @ptrCast (node )) },
76
76
.cdata_section = > .{ .CDATASection = @as (* parser .CDATASection , @ptrCast (node )) },
77
77
.processing_instruction = > .{ .ProcessingInstruction = @as (* parser .ProcessingInstruction , @ptrCast (node )) },
78
- .document = > .{ .HTMLDocument = @as (* parser .DocumentHTML , @ptrCast (node )) },
78
+ .document = > blk : {
79
+ const doc : * parser.Document = @ptrCast (node );
80
+ if (doc .is_html ) {
81
+ break :blk .{ .HTMLDocument = @as (* parser .DocumentHTML , @ptrCast (node )) };
82
+ }
83
+
84
+ break :blk .{ .Document = doc };
85
+ },
79
86
.document_type = > .{ .DocumentType = @as (* parser .DocumentType , @ptrCast (node )) },
80
87
.attribute = > .{ .Attr = @as (* parser .Attribute , @ptrCast (node )) },
81
88
.document_fragment = > .{ .DocumentFragment = @as (* parser .DocumentFragment , @ptrCast (node )) },
Original file line number Diff line number Diff line change @@ -61,5 +61,7 @@ test "Browser.webcomponents" {
61
61
},
62
62
63
63
.{ "main.innerHTML" , "<lightpanda-test>connected</lightpanda-test>" },
64
+ .{ "document.createElement('lightpanda-test').dataset" , "[object DataSet]" },
65
+ .{ "document.createElement('lightpanda-test.x').dataset" , "[object DataSet]" },
64
66
}, .{});
65
67
}
You can’t perform that action at this time.
0 commit comments