Skip to content

Commit

Permalink
Fixed URL detection error, fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdonnelly committed Nov 13, 2013
1 parent 41014fc commit 941a6f8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion MDHTMLLabel/MDHTMLLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ - (NSString *)detectURLsInText:(NSString *)text
{
if (match.resultType == NSTextCheckingTypeLink)
{
if (match.range.location > 6 && ![[text substringWithRange:NSMakeRange(match.range.location-6, 4)] isEqualToString:@"href"])
// if the URL location is greater than 6 (enough space for an anchor tag) and there's a 'href' before it, or if there's a closing anchor tag
// after it, then we dont wrap the URL in anchor tags
if (!(match.range.location > 6 && [[text substringWithRange:NSMakeRange(match.range.location-6, 4)] isEqualToString:@"href"])
&& (![[text substringWithRange:match.range] rangeOfString:@"a>"].length > 0))
{
text = [text stringByReplacingCharactersInRange:match.range
withString:[NSString stringWithFormat:@"<a href='%@'>%@</a>", match.URL.absoluteString, match.URL.absoluteString]];
Expand Down

0 comments on commit 941a6f8

Please sign in to comment.