Re: Converting an NSAttributedString into an html string
Re: Converting an NSAttributedString into an html string
- Subject: Re: Converting an NSAttributedString into an html string
- From: Gustavo Pizano <email@hidden>
- Date: Fri, 15 Jan 2010 15:44:36 +0100
HEllo all..
Sorry im such a lama... I solved.. I just needed to initialize a NSString not an NSAttributedString.. also, I excluded the tags that tIm not interested in
I usted the following.. and WOW... COCO its so great... it places the inline styles.. which is what I needed!!!
NSArray * exclude = [NSArray arrayWithObjects:@"doctype", @"html", @"head", @"body",@"xml",nil];
NSDictionary * htmlAtt = [NSDictionary dictionaryWithObjectsAndKeys:NSHTMLTextDocumentType,NSDocumentTypeDocumentAttribute,exclude,NSExcludedElementsDocumentAttribute,nil];
NSError * error;
NSData * htmlData = [_mString dataFromRange:NSMakeRange(0, [_mString length]) documentAttributes:htmlAtt error:&error];
//NSAttributedString * htmlString = [[NSAttributedString alloc] initWithHTML:htmlData documentAttributes:&htmlAtt];
NSString * sdat = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
Thanks
Gustavo
On Jan 15, 2010, at 2:00 PM, Gustavo Pizano wrote:
> Hello all.
>
> Well I asked this in the webkit list, to see how webkit does the trick, there Darin (thank if you are somewhere here also) told me that I could use the method :\
>
> - (NSData *)dataFromRange:(NSRange)range documentAttributes:(NSDictionary *)dict error:(NSError**)error
>
> from the NSAtributedString, so this is what I have done..
>
> NSDictionary * htmlAtt = [NSDictionary dictionaryWithObject:NSHTMLTextDocumentType forKey:NSDocumentTypeDocumentAttribute];
> NSError * error;
> NSData * htmlData = [_mString dataFromRange:NSMakeRange(0, [_mString length]) documentAttributes:htmlAtt error:&error];
> NSAttributedString * htmlString = [[NSAttributedString alloc] initWithData:htmlData options:nil documentAttributes:&htmlAtt error:&error];
>
> in htmlData, I have DATa .. :P. but know I need to get the html formatted string, I mean, if Im right and Darin understood my quesiton good, is .. will this return me something with the html tags.. let's say, I have in a NSAttributedString this HELLOHELLOHELLOHELLO... will I get the proper string with html tags as webkit does when saving something? if yes.. then wheat am I missing because right now Im getting the HELLOHELLOHELLOHELLO \n in the htmlString variable.
>
> Any help will be appreciated it..
>
> Thanks
>
>
> Gustavo
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden