As the title tells,now i can simple convert HTML into NSAttributedString
with initWithHTML:documentAttributes:
, but what i want to do here is reverse. Is there any 3rd party library to achieve this?
@implementation NSAttributedString(HTML) -(NSString *)htmlForAttributedString{ NSArray * exclude = [NSArray arrayWithObjects:@"doctype", @"html", @"head", @"body", @"xml", nil ]; NSDictionary * htmlAtt = [NSDictionary dictionaryWithObjectsAndKeys:NSHTMLTextDocumentType, NSDocumentTypeDocumentAttribute, exclude, NSExcludedElementsDocumentAttribute, nil ]; NSError * error; NSData * htmlData = [self dataFromRange:NSMakeRange(0, [self length]) documentAttributes:htmlAtt error:&error ]; //NSAttributedString * htmlString = [[NSAttributedString alloc]initWithHTML:htmlData documentAttributes:&htmlAtt]; NSString * htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding]; return htmlString; } @end