Skip to content

Commit 018abe0

Browse files
committed
dom: implement outerHTML
1 parent b186497 commit 018abe0

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/dom/element.zig

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const checkCases = jsruntime.test_utils.checkCases;
2626
const Variadic = jsruntime.Variadic;
2727

2828
const collection = @import("html_collection.zig");
29-
const writeChildren = @import("../browser/dump.zig").writeChildren;
29+
const dump = @import("../browser/dump.zig");
3030
const css = @import("css.zig");
3131

3232
const Node = @import("node.zig").Node;
@@ -102,7 +102,17 @@ pub const Element = struct {
102102
var buf = std.ArrayList(u8).init(alloc);
103103
defer buf.deinit();
104104

105-
try writeChildren(parser.elementToNode(self), buf.writer());
105+
try dump.writeChildren(parser.elementToNode(self), buf.writer());
106+
// TODO express the caller owned the slice.
107+
// https://github.com/lightpanda-io/jsruntime-lib/issues/195
108+
return buf.toOwnedSlice();
109+
}
110+
111+
pub fn get_outerHTML(self: *parser.Element, alloc: std.mem.Allocator) ![]const u8 {
112+
var buf = std.ArrayList(u8).init(alloc);
113+
defer buf.deinit();
114+
115+
try dump.writeNode(parser.elementToNode(self), buf.writer());
106116
// TODO express the caller owned the slice.
107117
// https://github.com/lightpanda-io/jsruntime-lib/issues/195
108118
return buf.toOwnedSlice();
@@ -470,4 +480,9 @@ pub fn testExecFn(
470480
.{ .src = "document.getElementById('para-empty').innerHTML.trim()", .ex = "<span id=\"para-empty-child\"></span>" },
471481
};
472482
try checkCases(js_env, &innerHTML);
483+
484+
var outerHTML = [_]Case{
485+
.{ .src = "document.getElementById('para').outerHTML", .ex = "<p id=\"para\"> And</p>" },
486+
};
487+
try checkCases(js_env, &outerHTML);
473488
}

0 commit comments

Comments
 (0)