Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions BRYHTMLParser/HTMLNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,57 +40,57 @@ typedef NS_ENUM(unsigned int, HTMLNodeType) {
@protocol HTMLNode <NSObject>

/// Returns the first child element
@property (nonatomic, readonly) id <HTMLNode> firstChild;
@property (nonatomic, readonly, nullable) id <HTMLNode> firstChild;

/// Returns the plaintext contents of node
@property (nonatomic, readonly, copy) NSString *contents;
@property (nonatomic, readonly, copy, nullable) NSString *contents;

/// Returns the plaintext contents of this node + all children
@property (nonatomic, readonly, copy) NSString *allContents;
@property (nonatomic, readonly, copy, nullable) NSString *allContents;

/// Returns the html contents of the node
@property (nonatomic, readonly, copy) NSString *rawContents;
@property (nonatomic, readonly, copy, nullable) NSString *rawContents;

/// Returns next sibling in tree
@property (nonatomic, readonly) id <HTMLNode> nextSibling;
@property (nonatomic, readonly, nullable) id <HTMLNode> nextSibling;

/// Returns previous sibling in tree
@property (nonatomic, readonly) id <HTMLNode> previousSibling;
@property (nonatomic, readonly, nullable) id <HTMLNode> previousSibling;

/// Returns the class name
@property (nonatomic, readonly, copy) NSString *className;
@property (nonatomic, readonly, copy, nullable) NSString *className;

/// Returns the tag name
@property (nonatomic, readonly, copy) NSString *tagName;
@property (nonatomic, readonly, copy, nullable) NSString *tagName;

/// Returns the parent
@property (nonatomic, readonly) id <HTMLNode> parent;
@property (nonatomic, readonly, nullable) id <HTMLNode> parent;

/// Returns the first level of children
@property (nonatomic, readonly, copy) NSArray *children;
@property (nonatomic, readonly, copy, nonnull) NSArray<id<HTMLNode>> *children;

/// Returns the node type if know
@property (nonatomic, readonly) HTMLNodeType nodetype;

/// Gets the attribute value matching tha name
- (NSString *)getAttributeNamed:(NSString *)name;
- (nullable NSString *)getAttributeNamed:(nonnull NSString *)name;

/// Find children with the specified tag name
- (NSArray *)findChildTags:(NSString *)tagName;
- (nonnull NSArray<id<HTMLNode>> *)findChildTags:(nonnull NSString *)tagName;

/// Looks for a tag name e.g. "h3"
- (id <HTMLNode>)findChildTag:(NSString *)tagName;
- (nullable id <HTMLNode>)findChildTag:(nonnull NSString *)tagName;

/// Returns a single child of class
- (id <HTMLNode>)findChildOfClass:(NSString *)className;
- (nullable id <HTMLNode>)findChildOfClass:(nonnull NSString *)className;

/// Returns all children of class
- (NSArray *)findChildrenOfClass:(NSString *)className;
- (nonnull NSArray<id<HTMLNode>> *)findChildrenOfClass:(nonnull NSString *)className;

/// Finds a single child with a matching attribute. Set `allowPartial` to match partial matches, e.g. <img src="http://www.google.com> [findChildWithAttribute:@"src" matchingName:"google.com" allowPartial:TRUE]
- (id <HTMLNode>)findChildWithAttribute:(NSString *)attribute matchingName:(NSString *)className allowPartial:(BOOL)partial;
- (nullable id <HTMLNode>)findChildWithAttribute:(nonnull NSString *)attribute matchingName:(nonnull NSString *)className allowPartial:(BOOL)partial;

/// Finds all children with a matching attribute
- (NSArray *)findChildrenWithAttribute:(NSString *)attribute matchingName:(NSString *)className allowPartial:(BOOL)partial;
- (nonnull NSArray<id<HTMLNode>> *)findChildrenWithAttribute:(nonnull NSString *)attribute matchingName:(nonnull NSString *)className allowPartial:(BOOL)partial;

@end
14 changes: 7 additions & 7 deletions BRYHTMLParser/HTMLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
@interface HTMLParser : NSObject

/// Returns the doc tag
@property (nonatomic, readonly) id <HTMLNode> doc;
@property (nonatomic, readonly, nullable) id <HTMLNode> doc;

/// Returns the body tag
@property (nonatomic, readonly) id <HTMLNode> body;
@property (nonatomic, readonly, nullable) id <HTMLNode> body;

/// Returns the html tag
@property (nonatomic, readonly) id <HTMLNode> html;
@property (nonatomic, readonly, nullable) id <HTMLNode> html;

/// Returns the head tag
@property (nonatomic, readonly) id <HTMLNode> head;
@property (nonatomic, readonly, nullable) id <HTMLNode> head;

- (instancetype)initWithContentsOfURL:(NSURL *)url error:(NSError **)error;
- (nullable instancetype)initWithContentsOfURL:(nonnull NSURL *)url error:(NSError * _Nullable * _Nullable)error;

- (instancetype)initWithData:(NSData *)data error:(NSError **)error NS_DESIGNATED_INITIALIZER;
- (nonnull instancetype)initWithData:(nonnull NSData *)data error:(NSError * _Nullable * _Nullable)error NS_DESIGNATED_INITIALIZER;

- (instancetype)initWithString:(NSString *)string error:(NSError **)error NS_DESIGNATED_INITIALIZER;
- (nonnull instancetype)initWithString:(nonnull NSString *)string error:(NSError * _Nullable * _Nullable)error NS_DESIGNATED_INITIALIZER;

@end
2 changes: 1 addition & 1 deletion BRYHTMLParser/LibXMLHTMLNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
struct _xmlNode;

/// Init with a lib xml node (shouldn't need to be called manually). Use [parser doc] to get the root Node
- (instancetype)initWithXMLNode:(struct _xmlNode *)xmlNode NS_DESIGNATED_INITIALIZER;
- (nonnull instancetype)initWithXMLNode:(struct _xmlNode * _Nullable)xmlNode NS_DESIGNATED_INITIALIZER;

@end