diff --git a/src/css/libdom.zig b/src/css/libdom.zig index 57d4af54..318e401c 100644 --- a/src/css/libdom.zig +++ b/src/css/libdom.zig @@ -28,4 +28,8 @@ pub const Node = struct { 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); + } }; diff --git a/src/css/libdom_test.zig b/src/css/libdom_test.zig index 5a952cfc..0e5a255d 100644 --- a/src/css/libdom_test.zig +++ b/src/css/libdom_test.zig @@ -36,11 +36,10 @@ test "matchFirst" { html: []const u8, exp: usize, }{ - .{ - .q = "address", - .html = "
This address...", - .exp = 1, - }, + .{ .q = "address", .html = "This address...", .exp = 1 }, + .{ .q = "#foo", .html = "", .exp = 1 }, + .{ .q = ".t1", .html = "
", .exp = 1 }, + .{ .q = ".t1", .html = "