diff --git a/HTMLKit/HTMLParser.m b/HTMLKit/HTMLParser.m index 941330e..333ce23 100644 --- a/HTMLKit/HTMLParser.m +++ b/HTMLKit/HTMLParser.m @@ -320,7 +320,12 @@ HTMLNode *adjustedInsertionLocation = [self appropriatePlaceForInsertingANodeWithOverrideTarget:nil beforeChildNode:&child]; if (adjustedInsertionLocation.type != HTMLNodeDocument) { -#warning Implement inserting string into node (https://html.spec.whatwg.org/multipage/syntax.html#insert-a-character) + if (adjustedInsertionLocation.lastChildNode.type == HTMLNodeText) { + [(HTMLText *)adjustedInsertionLocation.lastChildNode appendString:data]; + } else { + HTMLText *text = [[HTMLText alloc] initWithData:data]; + [adjustedInsertionLocation insertNode:text beforeChildNode:child]; + } } } diff --git a/HTMLKit/HTMLText.h b/HTMLKit/HTMLText.h index 469b11b..fcc6075 100644 --- a/HTMLKit/HTMLText.h +++ b/HTMLKit/HTMLText.h @@ -14,4 +14,6 @@ - (instancetype)initWithData:(NSString *)data; +- (void)appendString:(NSString *)string; + @end diff --git a/HTMLKit/HTMLText.m b/HTMLKit/HTMLText.m index 1150a08..06de445 100644 --- a/HTMLKit/HTMLText.m +++ b/HTMLKit/HTMLText.m @@ -35,6 +35,11 @@ [self.data setString:textContent ?: @""]; } +- (void)appendString:(NSString *)string +{ + [self.data appendString:string]; +} + #pragma mark - NSCopying - (id)copyWithZone:(NSZone *)zone