css: add isDocument, isText and isComment

This commit is contained in:
Pierre Tachoire
2024-03-25 17:38:21 +01:00
parent 8a91840783
commit 2c7650cdb1
3 changed files with 29 additions and 2 deletions

View File

@@ -46,6 +46,21 @@ pub const Node = struct {
return t == .element;
}
pub fn isDocument(n: Node) bool {
const t = parser.nodeType(n.node) catch return false;
return t == .document;
}
pub fn isComment(n: Node) bool {
const t = parser.nodeType(n.node) catch return false;
return t == .comment;
}
pub fn isText(n: Node) bool {
const t = parser.nodeType(n.node) catch return false;
return t == .text;
}
pub fn tag(n: Node) ![]const u8 {
return try parser.nodeName(n.node);
}