diff --git a/HTMLKit/HTMLNamespaces.h b/HTMLKit/HTMLNamespaces.h index 112161e..fb7badd 100644 --- a/HTMLKit/HTMLNamespaces.h +++ b/HTMLKit/HTMLNamespaces.h @@ -6,8 +6,18 @@ // Copyright (c) 2014 BrainCookie. All rights reserved. // +/** + HTML Namespaces + https://html.spec.whatwg.org/multipage/infrastructure.html#namespaces + */ typedef NS_ENUM(NSInteger, HTMLNamespace) { + /** The default HTML namespace. */ HTMLNamespaceHTML, + + /** The namespace for most of the elements. */ HTMLNamespaceMathML, + + /** The namespace for most of the elements. */ + HTMLNamespaceSVG }; diff --git a/HTMLKit/HTMLNodeFilter.h b/HTMLKit/HTMLNodeFilter.h index e90cd86..376f885 100644 --- a/HTMLKit/HTMLNodeFilter.h +++ b/HTMLKit/HTMLNodeFilter.h @@ -10,6 +10,10 @@ NS_ASSUME_NONNULL_BEGIN +/** + The node filter's value when applied to a given HTML node. The node filter can either accept a node, skip it, or + reject it. Rejecting a node means skipping the node itself and all of it descendants. + */ typedef NS_ENUM(unsigned short, HTMLNodeFilterValue) { HTMLNodeFilterAccept = 1, @@ -17,6 +21,12 @@ typedef NS_ENUM(unsigned short, HTMLNodeFilterValue) HTMLNodeFilterSkip = 3 }; +/** + The show options for the HTML node iterator and tree walker. + + @see HTMLNodeIterator + @see HTMLTreeWalker + */ typedef NS_OPTIONS(unsigned long, HTMLNodeFilterShowOptions) { HTMLNodeFilterShowAll = 0xFFFFFFFF, @@ -33,16 +43,36 @@ typedef NS_OPTIONS(unsigned long, HTMLNodeFilterShowOptions) @class HTMLNode; +/** + A HTML Node Filter which can be used with a node iterator or a tree walker. + + @see HTMLNodeIterator + @see HTMLTreeWalker + */ @protocol HTMLNodeFilter - +@required +/** + The implementation should return a HTMLNodeFilterValue to indicate accepting, skipping or rejecting a node. + + @param node The node to be filtered. + @returns `HTMLNodeFilterAccept` if accepted, `HTMLNodeFilterSkip` if skipped, or `HTMLNodeFilterReject` if rejected. + */ - (HTMLNodeFilterValue)acceptNode:(HTMLNode *)node; @end #pragma mark - Block Filter +/** + A concrete block-based HTML Node Filter implementation. + */ @interface HTMLNodeFilterBlock : NSObject +/** + Initializes and returns a new instance of this filter. + + @param block The block to apply on each node to be filtered. + */ + (instancetype)filterWithBlock:(HTMLNodeFilterValue (^)(HTMLNode *node))block; @end @@ -51,8 +81,16 @@ typedef NS_OPTIONS(unsigned long, HTMLNodeFilterShowOptions) @class CSSSelector; +/** + A concrete css-selector-based HTML Node Filter implementation. + */ @interface HTMLSelectorNodeFilter : NSObject +/** + Initializes and returns a new instance of this filter. + + @param selector The selector to apply on each node to be filtered. + */ + (instancetype)filterWithSelector:(CSSSelector *)selector; @end diff --git a/HTMLKit/HTMLNodeIterator.h b/HTMLKit/HTMLNodeIterator.h index f8af8a6..946aeb7 100644 --- a/HTMLKit/HTMLNodeIterator.h +++ b/HTMLKit/HTMLNodeIterator.h @@ -13,26 +13,81 @@ NS_ASSUME_NONNULL_BEGIN @class HTMLNode; +/** + A HTML Node Iterator, which iterates the nodes in the DOM in tree order, i.e. depth-first traversal of the tree. + + https://dom.spec.whatwg.org/#interface-nodeiterator + */ @interface HTMLNodeIterator : NSEnumerator +/** + The root element of this iterator, i.e. the traversed tree is rooted at this element. + */ @property (nonatomic, strong, readonly) HTMLNode *root; + +/** + The current reference node. + */ @property (nonatomic, strong, readonly) HTMLNode *referenceNode; + +/** + Whether the iterator's pointer is before the reference node. + */ @property (nonatomic, assign, readonly) BOOL pointerBeforeReferenceNode; + +/** + The iterator's show options. These options control what types of elements are shown or skipped during iteration. + + @see HTMLNodeFilterShowOptions + */ @property (nonatomic, assign, readonly) HTMLNodeFilterShowOptions whatToShow; -@property (nonatomic, strong, readonly) id filter; -+ (instancetype)iteratorWithNode:(HTMLNode *)node - showOptions:(HTMLNodeFilterShowOptions)showOptions - filter:(nullable HTMLNodeFilterValue (^)(HTMLNode *node))filter; +/** + A node filter, that is applied to each node during iteration. + @see HTMLNodeFilter + */ +@property (nonatomic, strong, readonly, nullable) id filter; + + +/** + Initializes a new node iterator with no filter and HTMLNodeFilterShowAll show options. + + @param node The root node. + @returns A new instance of a node iterator. + */ - (instancetype)initWithNode:(HTMLNode *)node; + +/** + Initializes a new node iterator with HTMLNodeFilterShowAll show options. + + @param node The root node. + @param filter The node filter to use. + @returns A new instance of a node iterator. + */ - (instancetype)initWithNode:(HTMLNode *)node filter:(nullable id)filter; + +/** + Initializes a new node iterator. + + @param node The root node. + @param showOptions The show options for the iterator. + @param filter The node filter to use. + @returns A new instance of a node iterator. + */ - (instancetype)initWithNode:(HTMLNode *)node showOptions:(HTMLNodeFilterShowOptions)showOptions filter:(nullable id)filter; +/** + @returns The next iterated node in tree order, `nil` if there are no more nodes to iterate. + */ - (nullable HTMLNode *)nextNode; + +/** + @returns The previous iterated node in tree order, `nil` if there are no more nodes to iterate. + */ - (nullable HTMLNode *)previousNode; @end diff --git a/HTMLKit/HTMLNodeTraversal.h b/HTMLKit/HTMLNodeTraversal.h index ee2bf7e..bd40058 100644 --- a/HTMLKit/HTMLNodeTraversal.h +++ b/HTMLKit/HTMLNodeTraversal.h @@ -6,6 +6,10 @@ // Copyright (c) 2015 BrainCookie. All rights reserved. // +///------------------------------------------------------ +/// HTMLKit private header +///------------------------------------------------------ + #import #import "HTMLNodeFilter.h" diff --git a/HTMLKit/HTMLQuirksMode.h b/HTMLKit/HTMLQuirksMode.h index 3ad4920..2c6008d 100644 --- a/HTMLKit/HTMLQuirksMode.h +++ b/HTMLKit/HTMLQuirksMode.h @@ -8,6 +8,10 @@ #import "NSString+HTMLKit.h" +/** + HTML quirks modes + https://html.spec.whatwg.org/multipage/infrastructure.html#quirks-mode + */ typedef NS_ENUM(short, HTMLQuirksMode) { HTMLQuirksModeNoQuirks, diff --git a/HTMLKit/HTMLTreeWalker.h b/HTMLKit/HTMLTreeWalker.h index ac425c6..07a7f08 100644 --- a/HTMLKit/HTMLTreeWalker.h +++ b/HTMLKit/HTMLTreeWalker.h @@ -13,26 +13,102 @@ NS_ASSUME_NONNULL_BEGIN @class HTMLNode; +/** + A HTML Tree Walker. Used to "walk" the DOM tree in all directions, i.e. it can traverse from a given node to its parent, + child, next, or previous sibling. + + https://dom.spec.whatwg.org/#interface-treewalker + */ @interface HTMLTreeWalker : NSObject +/** + The root element of this tree walker, i.e. the traversed tree is rooted at this element. + */ @property (nonatomic, strong, readonly) HTMLNode *root; + +/** + The iterator's show options. These options control what types of elements are shown or skipped during tree walking. + + @see HTMLNodeFilterShowOptions + */ @property (nonatomic, assign, readonly) HTMLNodeFilterShowOptions whatToShow; + +/** + A node filter, that is applied to each node during tree walking. + + @see HTMLNodeFilter + */ @property (nonatomic, strong, readonly, nullable) id filter; + +/** + The current node at which this walker is standing. + */ @property (nonatomic, strong) HTMLNode *currentNode; +/** + Initializes a new tree walker with no filter and HTMLNodeFilterShowAll show options. + + @param node The root node. + @param filter The node filter to use. + @returns A new instance of a tree walker. + */ - (instancetype)initWithNode:(HTMLNode *)node; + +/** + Initializes a new tree walker with HTMLNodeFilterShowAll show options. + + @param node The root node. + @param filter The node filter to use. + @returns A new instance of a tree walker. + */ - (instancetype)initWithNode:(HTMLNode *)node filter:(nullable id)filter; + +/** + Initializes a new tree walker. + + @param node The root node. + @param showOptions The show options for the walker. + @param filter The node filter to use. + @returns A new instance of a tree walker. + */ - (instancetype)initWithNode:(HTMLNode *)node showOptions:(HTMLNodeFilterShowOptions)showOptions filter:(nullable id)filter; +/** + The parent node of the current node. + */ - (nullable HTMLNode *)parentNode; + +/** + The first child node of the current node. + */ - (nullable HTMLNode *)firstChild; + +/** + The last child node of the current node. + */ - (nullable HTMLNode *)lastChild; + +/** + The previous sibling node of the current node. + */ - (nullable HTMLNode *)previousSibling; + +/** + The next sibling node of the current node. + */ - (nullable HTMLNode *)nextSibling; + +/** + The previous node of the current node in tree order. + */ - (nullable HTMLNode *)previousNode; + +/** + The next node of the current node in tree order. + */ - (nullable HTMLNode *)nextNode; @end