mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-01-30 17:23:53 -05:00
36 lines
880 B
Zig
36 lines
880 B
Zig
const std = @import("std");
|
|
|
|
const parser = @import("../netsurf.zig");
|
|
|
|
// Node implementation with Netsurf Libdom C lib.
|
|
pub const Node = struct {
|
|
node: *parser.Node,
|
|
|
|
pub fn firstChild(n: Node) !?Node {
|
|
const c = try parser.nodeFirstChild(n.node);
|
|
if (c) |cc| return .{ .node = cc };
|
|
|
|
return null;
|
|
}
|
|
|
|
pub fn nextSibling(n: Node) !?Node {
|
|
const c = try parser.nodeNextSibling(n.node);
|
|
if (c) |cc| return .{ .node = cc };
|
|
|
|
return null;
|
|
}
|
|
|
|
pub fn isElement(n: Node) bool {
|
|
const t = parser.nodeType(n.node) catch return false;
|
|
return t == .element;
|
|
}
|
|
|
|
pub fn tag(n: Node) ![]const u8 {
|
|
return try parser.nodeName(n.node);
|
|
}
|
|
|
|
pub fn attr(n: Node, key: []const u8) !?[]const u8 {
|
|
return try parser.elementGetAttribute(parser.nodeToElement(n.node), key);
|
|
}
|
|
};
|