Closed kevinrenskers closed 8 years ago
I am now combining this project with TTTAttributedLabel to handle the inline kind of links, and also for the actual click handling. Feels a bit overpowered but it does the job.
I'd much rather have TSMarkdownParser handle all link detection though, then I only need a lighter weight UILabel that handles clicks on links (NSLinkAttributeName). Any suggestions for such a thing? :)
TTTAttributedLabel is roughly doing it like this (for a UILabel):
NSDataDetector *dataDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSMutableAttributedString *mutableAttributedString = [self.attributedText mutableCopy];
NSArray *results = [dataDetector matchesInString:self.attributedText.string options:0 range:NSMakeRange(0, self.attributedText.length)];
for (NSTextCheckingResult *result in results) {
NSString *linkURLString = [self.attributedText.string substringWithRange:result.range];
[mutableAttributedString addAttribute:NSLinkAttributeName
value:[NSURL URLWithString:linkURLString]
range:result.range];
}
self.attributedText = mutableAttributedString;
Let's include the feature for 2.0 I'm working on it today.
I've added the feature to branch 2.0.
@kevinrenskers, please note that TSMarkdownParser 2.0.1 is now ofifically available on CocoaPods
When the text has
[links like this](http://example.com)
everything works fine.But in the case the text
is just a link: http://example.com
then the link isn't detected, like it would be on GitHub for example. Is this easy to add?