| 91 | | NSMutableAttributedString *result = nil; |
|---|
| 92 | | if( NSAppKitVersionNumber >= 700. ) { |
|---|
| 93 | | // the rgba CSS makes WebKit give colorless text where no color was specified (instead of black) |
|---|
| 94 | | NSString *render = [NSString stringWithFormat:@"<span style=\"color: rgba( 0, 0, 0, 0.0 )\">%@</span>", fragment]; |
|---|
| 95 | | result = [[NSMutableAttributedString alloc] initWithHTML:[render dataUsingEncoding:NSUTF8StringEncoding] options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1], @"UseWebKit", @"utf-8", @"TextEncodingName", url, @"BaseURL", nil] documentAttributes:NULL]; |
|---|
| 96 | | } else { |
|---|
| 97 | | NSString *render = [NSString stringWithFormat:@"<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /></head><body>%@</body></html>", fragment]; |
|---|
| 98 | | result = [[NSAttributedString alloc] initWithHTML:[render dataUsingEncoding:NSUTF8StringEncoding] baseURL:url documentAttributes:NULL]; |
|---|
| | 91 | NSMutableDictionary *options = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1], @"UseWebKit", @"utf-8", @"TextEncodingName", nil]; |
|---|
| | 92 | if( url ) [options setObject:url forKey:@"BaseURL"]; |
|---|
| | 93 | |
|---|
| | 94 | // we suround the fragment in the #01fe02 green color so we can later key it out and strip it |
|---|
| | 95 | // this will result in colorless areas of our string, letting the color be defined by the interface |
|---|
| | 96 | |
|---|
| | 97 | NSString *render = [NSString stringWithFormat:@"<span style=\"color: #01fe02\">%@</span>", fragment]; |
|---|
| | 98 | NSMutableAttributedString *result = [[NSMutableAttributedString alloc] initWithHTML:[render dataUsingEncoding:NSUTF8StringEncoding] options:options documentAttributes:NULL]; |
|---|
| | 99 | |
|---|
| | 100 | NSRange limitRange, effectiveRange; |
|---|
| | 101 | limitRange = NSMakeRange( 0, [result length] ); |
|---|
| | 102 | while( limitRange.length > 0 ) { |
|---|
| | 103 | NSColor *color = [result attribute:NSForegroundColorAttributeName atIndex:limitRange.location longestEffectiveRange:&effectiveRange inRange:limitRange]; |
|---|
| | 104 | if( [[color HTMLAttributeValue] isEqualToString:@"#01fe02"] ) // strip the color if it matched |
|---|
| | 105 | [result removeAttribute:NSForegroundColorAttributeName range:effectiveRange]; |
|---|
| | 106 | limitRange = NSMakeRange( NSMaxRange( effectiveRange ), NSMaxRange( limitRange ) - NSMaxRange( effectiveRange ) ); |
|---|