Skip to content

Commit

Permalink
Make body element easily accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
Newspad authored and nolanw committed Feb 3, 2016
1 parent 1f3a990 commit 58c0dca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Code/HTMLDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (strong, nonatomic) HTMLElement * __nullable rootElement;

/**
The first child element of the root with the tag name `body`. Typically the `<body>` element.
*/
@property (readonly, nonatomic) HTMLElement * __nullable bodyElement;

@end

NS_ASSUME_NONNULL_END
13 changes: 13 additions & 0 deletions Code/HTMLDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ - (void)setRootElement:(HTMLElement * __nullable)rootElement
}
}

- (HTMLElement * __nullable)bodyElement
{
for (id child in self.rootElement.children) {
if ([child isKindOfClass:[HTMLElement class]]) {
HTMLElement *elem = child;
if ([elem.tagName isEqualToString:@"body"]) {
return elem;
}
}
}
return nil;
}

static id FirstNodeOfType(id <NSFastEnumeration> collection, Class type)
{
for (id node in collection) {
Expand Down

0 comments on commit 58c0dca

Please sign in to comment.