css: add isEmptyText in node interface

This commit is contained in:
Pierre Tachoire
2024-03-25 17:45:19 +01:00
parent 2c7650cdb1
commit 4e61a50946
3 changed files with 16 additions and 2 deletions

View File

@@ -61,6 +61,14 @@ pub const Node = struct {
return t == .text;
}
pub fn isEmptyText(n: Node) !bool {
const data = try parser.nodeTextContent(n.node);
if (data == null) return true;
if (data.?.len == 0) return true;
return std.mem.trim(u8, data.?, &std.ascii.whitespace).len == 0;
}
pub fn tag(n: Node) ![]const u8 {
return try parser.nodeName(n.node);
}