Just because I noticed it break the tags to where it overflows, it now just uses the tag cleaner for finding out the link. Yes this can infact cause a problem if there is a span tag inside the link, but I am not to sure if I want to spend the time to detect inner tags. I think people won't mind if the link sometimes ends up being with the image.

This commit is contained in:
GRMrGecko 2011-02-14 05:51:33 -06:00
parent cc420e9c72
commit 1d6b5dad8d

View File

@ -48,13 +48,13 @@ NSString * const MGMAIAllowStrangers = @"MGMAIAllowStrangers";
continue;
range.location = linkStartRange.location+linkStartRange.length;
range.length = [html length]-range.location;
NSRange linkReplaceEndRange = [html rangeOfString:@"<" options:NSCaseInsensitiveSearch range:range];
NSRange linkEndRange = [html rangeOfString:@"</a" options:NSCaseInsensitiveSearch range:range];
if (linkEndRange.location==NSNotFound)
continue;
range.location = linkEndRange.location+linkEndRange.length;
range.length = [html length]-range.location;
linkRange = NSMakeRange(linkStartRange.location+linkStartRange.length, linkEndRange.location-(linkStartRange.location+linkStartRange.length));
NSMutableString *link = [[html substringWithRange:linkRange] mutableCopy];
NSMutableString *link = [[html substringWithRange:NSMakeRange(linkStartRange.location+linkStartRange.length, linkEndRange.location-(linkStartRange.location+linkStartRange.length))] mutableCopy];
NSRange tagRange = NSMakeRange(0, [link length]);
while (YES) {
NSRange tagStartRange = [link rangeOfString:@"<" options:NSCaseInsensitiveSearch range:tagRange];
@ -75,8 +75,9 @@ NSString * const MGMAIAllowStrangers = @"MGMAIAllowStrangers";
shouldScroll = [webview stringByEvaluatingJavaScriptFromString:@"nearBottom();"];
}
NSString *image = [NSString stringWithFormat:@"<img src=\"%@\" style=\"max-width: 100%%; max-height: 100%%;\" onLoad=\"imageSwap(this, false);alignChat(%@);\" />", link, shouldScroll];
[html replaceCharactersInRange:linkRange withString:image];
range.location += [image length]-linkRange.length;
NSRange replaceRange = NSMakeRange(linkStartRange.location+linkStartRange.length, linkReplaceEndRange.location-(linkStartRange.location+linkStartRange.length));
[html replaceCharactersInRange:replaceRange withString:image];
range.location += [image length]-replaceRange.length;
range.length = [html length]-range.location;
}
[link release];