diff --git a/Sources/HTMLComment.m b/Sources/HTMLComment.m
index c126999..170f025 100644
--- a/Sources/HTMLComment.m
+++ b/Sources/HTMLComment.m
@@ -35,6 +35,11 @@
self.data = textContent ?: @"";
}
+- (NSUInteger)length
+{
+ return self.data.length;
+}
+
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
diff --git a/Sources/HTMLDocumentType.m b/Sources/HTMLDocumentType.m
index 8a4636c..c22be69 100644
--- a/Sources/HTMLDocumentType.m
+++ b/Sources/HTMLDocumentType.m
@@ -129,6 +129,11 @@ NS_INLINE BOOL nilOrEqual(id first, id second) {
return HTMLQuirksModeNoQuirks;
}
+- (NSUInteger)length
+{
+ return 0;
+}
+
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
diff --git a/Sources/HTMLNode.m b/Sources/HTMLNode.m
index 83291d7..7e597ec 100644
--- a/Sources/HTMLNode.m
+++ b/Sources/HTMLNode.m
@@ -123,6 +123,11 @@
return nil;
}
+- (NSUInteger)length
+{
+ return self.childNodesCount;
+}
+
#pragma mark - Cast
- (HTMLElement *)asElement
@@ -155,6 +160,11 @@
return self.childNodes.count;
}
+- (BOOL)isEmpty
+{
+ return self.length == 0;
+}
+
- (HTMLNode *)childNodeAtIndex:(NSUInteger)index
{
return [self.childNodes objectAtIndex:index];
diff --git a/Sources/HTMLText.m b/Sources/HTMLText.m
index 55daaae..a56ed51 100644
--- a/Sources/HTMLText.m
+++ b/Sources/HTMLText.m
@@ -42,6 +42,11 @@
[self.data appendString:string];
}
+- (NSUInteger)length
+{
+ return self.data.length;
+}
+
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
diff --git a/Sources/include/HTMLNode.h b/Sources/include/HTMLNode.h
index da1a5c5..bc74b5a 100644
--- a/Sources/include/HTMLNode.h
+++ b/Sources/include/HTMLNode.h
@@ -137,6 +137,11 @@ typedef NS_ENUM(unsigned short, HTMLDocumentPosition)
*/
@property (nonatomic, copy) NSString *innerHTML;
+/**
+ The length of the node as described in https://dom.spec.whatwg.org/#concept-node-length
+ */
+@property (nonatomic, assign) NSUInteger length;
+
/**
@abstract Use concrete subclasses of the HTML Node.
*/
@@ -164,6 +169,13 @@ typedef NS_ENUM(unsigned short, HTMLDocumentPosition)
*/
- (NSUInteger)childNodesCount;
+/**
+ Checks whether the node is empty as described in https://dom.spec.whatwg.org/#concept-node-length
+
+ @return `YES` if the node is empty, `NO` otherwise.
+ */
+- (BOOL)isEmpty;
+
/**
Returns the child node at a given index.