I'm trying to feed Mail.app some simple html: lists, bold font, some italics. However, I noticed that if I use characters like £
, then Mail.app just doesn't show anything. I realized I need to convert to HTML entities, like £
(full list here: http://www.w3schools.com/tags/ref_entities.asp). I have a partial solution that works for most characters my users have come up with, but it's far from being a solid fix:
- (NSString*) makeValidHTML:(NSString*)str {
str = [str stringByReplacingOccurrencesOfString:@"£" withString:@"£"];
str = [str stringByReplacingOccurrencesOfString:@"¢" withString:@"¢"];
str = [str stringByReplacingOccurrencesOfString:@"¥" withString:@"¥"];
str = [str stringByReplacingOccurrencesOfString:@"©" withString:@"©"];
str = [str stringByReplacingOccurrencesOfString:@"®" withString:@"®"];
str = [str stringByReplacingOccurrencesOfString:@"°" withString:@"°"];
str = [str stringByReplacingOccurrencesOfString:@"¿" withString:@"¿"];
str = [str stringByReplacingOccurrencesOfString:@"¡" withString:@"¡"];
str = [str stringByReplacingOccurrencesOfString:@"‘" withString:@"'"];
str = [str stringByReplacingOccurrencesOfString:@"'" withString:@"'"];
str = [str stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
str = [str stringByReplacingOccurrencesOfString:@"\"" withString:@"""];
str = [str stringByReplacingOccurrencesOfString:@"“" withString:@"""];
str = [str stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
str = [str stringByReplacingOccurrencesOfString:@">" withString:@">"];
return str;
}
Is there a standard way to do this without having to list every possible reserved character?