Closed guidedways closed 6 years ago
Given the following code:
- (NSAttributedString *)attributedStringFromHTML:(NSString *)html { NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding]; DTHTMLAttributedStringBuilder*stringBuilder = [[DTHTMLAttributedStringBuilder alloc] initWithHTML:data options:nil documentAttributes:NULL]; return [stringBuilder generatedAttributedString]; } NSAttributedString *string = [self attributedStringFromHTML:@"Need to <b>contact</b> John <john@email.com> using Skype <http://www.skype.com>"]; NSString *plain = [string string]; NSLog(@"%@", plain);
I get:
Need to contact John using Skype
I need this to be:
Need to contact John <john@email.com> using Skype <http://www.skype.com>
Is this possible? I need to retain any non-html 'tags'. Input is free-form notes from a user that I need to parse effectively turning HTML into plainText.
Given the following code:
I get:
I need this to be:
Is this possible? I need to retain any non-html 'tags'. Input is free-form notes from a user that I need to parse effectively turning HTML into plainText.