Fix the returned object of the fragment parsing algorithm
- Return a non-nil empty array instead of nil when context element is nil - Return a copy of the document root's child nodes instead of the "view"-array - Use the root selector instead of the index-based access when rerunning the algorithm with the same context element
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#import "HTMLElementAdjustment.h"
|
||||
#import "HTMLMarker.h"
|
||||
#import "NSString+HTMLKit.h"
|
||||
#import "CSSSelectors.h"
|
||||
|
||||
@interface HTMLTokenizer (Private)
|
||||
@property (nonatomic, weak) HTMLParser *parser;
|
||||
@@ -124,11 +125,12 @@
|
||||
- (NSArray *)parseFragmentWithContextElement:(HTMLElement *)contextElement
|
||||
{
|
||||
if (contextElement == nil) {
|
||||
return nil;
|
||||
return @[];
|
||||
}
|
||||
|
||||
if ([_contextElement isEqual:contextElement]) {
|
||||
return [_document childNodeAtIndex:0].childNodes.array;
|
||||
HTMLElement *root = [_document firstElementMatchingSelector:rootSelector()];
|
||||
return root? root.childNodes.objectEnumerator.allObjects: @[];
|
||||
}
|
||||
|
||||
[self initializeDocument];
|
||||
@@ -173,7 +175,7 @@
|
||||
|
||||
[self runParser];
|
||||
|
||||
return root.childNodes.array;
|
||||
return root.childNodes.objectEnumerator.allObjects;
|
||||
}
|
||||
|
||||
- (void)runParser
|
||||
|
||||
Reference in New Issue
Block a user