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 {
6060
6161 pub fn toInterfaceT (comptime T : type , e : * parser.Element ) ! T {
6262 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+
6469 return .{ .Element = e };
6570 };
6671
6772 // TODO SVGElement and MathML are not supported yet.
6873
6974 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+
7181 return .{ .Element = e };
7282 };
7383
Original file line number Diff line number Diff line change @@ -75,7 +75,14 @@ pub const Node = struct {
7575 .text = > .{ .Text = @as (* parser .Text , @ptrCast (node )) },
7676 .cdata_section = > .{ .CDATASection = @as (* parser .CDATASection , @ptrCast (node )) },
7777 .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+ },
7986 .document_type = > .{ .DocumentType = @as (* parser .DocumentType , @ptrCast (node )) },
8087 .attribute = > .{ .Attr = @as (* parser .Attribute , @ptrCast (node )) },
8188 .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" {
6161 },
6262
6363 .{ "main.innerHTML" , "<lightpanda-test>connected</lightpanda-test>" },
64+ .{ "document.createElement('lightpanda-test').dataset" , "[object DataSet]" },
65+ .{ "document.createElement('lightpanda-test.x').dataset" , "[object DataSet]" },
6466 }, .{});
6567}
You can’t perform that action at this time.
0 commit comments