mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
css: add isEmptyText in node interface
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ pub const Node = struct {
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn isEmptyText(_: *const Node) !bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn tag(n: *const Node) ![]const u8 {
|
||||
return n.name;
|
||||
}
|
||||
|
||||
@@ -383,8 +383,10 @@ pub const Selector = union(enum) {
|
||||
while (c != null) {
|
||||
if (c.?.isElement()) return false;
|
||||
|
||||
// TODO check text node content equals an empty
|
||||
// string ("")
|
||||
if (c.?.isText()) {
|
||||
if (try c.?.isEmptyText()) continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
c = try c.?.nextSibling();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user