Add implementation for text-content in the HTML Element

This commit is contained in:
iska
2015-04-08 00:29:00 +02:00
parent 72efa18a22
commit d6f5434ab8
5 changed files with 33 additions and 4 deletions
+4
View File
@@ -46,6 +46,10 @@
- (HTMLNode *)adoptNode:(HTMLNode *)node
{
if (node == nil) {
return nil;
}
if (node.type == HTMLNodeDocument) {
[NSException raise:HTMLKitNotSupportedError
format:@"%@: Not Fount Error, adopting a document node. The operation is not supported.", NSStringFromSelector(_cmd)];
+16 -3
View File
@@ -7,9 +7,11 @@
//
#import "HTMLElement.h"
#import "HTMLDocument.h"
#import "HTMLText.h"
#import "HTMLOrderedDictionary.h"
#import "NSString+HTMLKit.h"
#import "HTMLText.h"
@interface HTMLElement ()
{
@@ -84,8 +86,19 @@
- (NSString *)textContent
{
#warning Implement Traversing
return nil;
NSMutableString *content = [NSMutableString string];
for (HTMLNode *node in self.treeEnumerator) {
if (node.type == HTMLNodeText) {
[content appendString:[(HTMLText *)node data]];
}
}
return content;
}
- (void)setTextContent:(NSString *)textContent
{
HTMLText *node = [[HTMLText alloc] initWithData:textContent];
[self replaceAllChildNodesWithNode:node];
}
#pragma mark - NSCopying
+2
View File
@@ -73,6 +73,8 @@ typedef NS_ENUM(short, HTMLNodeType)
- (HTMLNode *)replaceChildNode:(HTMLNode *)node withNode:(HTMLNode *)replacement;
- (void)replaceAllChildNodesWithNode:(HTMLNode *)node;
- (HTMLNode *)removeChildNode:(HTMLNode *)node;
- (HTMLNode *)removeChildNodeAtIndex:(NSUInteger)index;
+10
View File
@@ -165,6 +165,16 @@
return child;
}
- (void)replaceAllChildNodesWithNode:(HTMLNode *)node
{
[self removeAllChildNodes];
if (node != nil) {
[self.ownerDocument adoptNode:node];
[self insertNode:node beforeChildNode:nil];
}
}
- (HTMLNode *)removeChildNode:(HTMLNode *)child
{
if (child.parentNode != self) {
+1 -1
View File
@@ -21,7 +21,7 @@
{
self = [super initWithName:@"#text" type:HTMLNodeText];
if (self) {
_data = [[NSMutableString alloc] initWithString:data];
_data = [[NSMutableString alloc] initWithString:data ?: @""];
}
return self;
}