Add HTML Text node

https://dom.spec.whatwg.org/#interface-text
This commit is contained in:
iska
2015-02-26 23:41:42 +01:00
parent fade192485
commit 034a28deea
3 changed files with 74 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
//
// HTMLText.h
// HTMLKit
//
// Created by Iska on 26/02/15.
// Copyright (c) 2015 BrainCookie. All rights reserved.
//
#import "HTMLNode.h"
@interface HTMLText : HTMLNode
@property (nonatomic, copy) NSMutableString *data;
- (instancetype)initWithData:(NSString *)data;
@end
+47
View File
@@ -0,0 +1,47 @@
//
// HTMLText.m
// HTMLKit
//
// Created by Iska on 26/02/15.
// Copyright (c) 2015 BrainCookie. All rights reserved.
//
#import "HTMLText.h"
@implementation HTMLText
- (instancetype)init
{
return [self initWithData:@""];
}
- (instancetype)initWithData:(NSString *)data
{
self = [super initWithName:@"#text" type:HTMLNodeText];
if (self) {
self.data = [NSMutableString new];
[self.data setString:data ?: @""];
}
return self;
}
- (NSString *)textContent
{
return [self.data copy];
}
- (void)setTextContent:(NSString *)textContent
{
[self.data setString:textContent ?: @""];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
HTMLText *copy = [super copyWithZone:zone];
copy.data = self.data;
return copy;
}
@end