|
AutoHyperlinks
On Building and Using the AutoHyperlinks Frameowrk.
AutoHyperlinks.frameworkAutoHyperlinks is the framework used by some programs, like Adium, to scan for URLs in strings and other text containers. This framework is released under the modified BSD license, and is free to be used in most any software project. What, exactly, does AutoHyperlinks do?The AutoHyperlinks framework handles the detection of hyperlinks in normal language, leaving you, the developer, free to concentrate on the core functionality of your application. It's the same code we use in Adium to match all our hyperlinks, and we think it's pretty great. AutoHyperlinks gives you a framework with a flex based lexer and two Objective-C classes in it: AHMarkedHyperlink and AHHyperlinkScanner. Together, these two classes can work together to identify and add the NSLinkAttributeNames like Adium does, or you can simply gather all the links strings and do whatever you want with them. How do I get it?Right here in maccode. See WhatIsMacCode. How do I use it in my project?To use AutoHyperlinks in your existing project, take the following steps:
What does it Include?You're given two classes to work with: AHMarkedHyperlink and AHHyperlinkScanner. It's sole dependency is the system Cocoa.framework, and is technically compatible down to OS X 10.3 (though we recommend 10.4 or later). AHMarkedHyperlinkAHMarkedHyperlink is a data type that holds onto information about each link; such as a NSURL object, a reference to it's parent string, and the link's range within that string. It also holds the links verification status as defined in AHLinkLexer.h so you know what type of link it is. AHHyperlinkScannerAHHyperlinkScanner is the main interface to all of the framework's link detection abilities. It has two parsing modes: strict and non-strict. Strict Mode:: This is the default mode. Only proper URIs with specified schemes (http://example.com/ but not example.com) will get identified as links. Non-Strict Mode:: Setting strict checking to NO removes this restriction, so example.com is included as a link, as well as http://example.com/. Class Methods:+hyperlinkScannerWithString: Creates a non-strict instance of AHHyperlinkScanner with a given NSString.+strictHyperlinkScannerWithString: Creates a strict instance of AHHyperlinkScanner with a given NSString.+hyperlinkScannerWithAttributedString: Creates a non-strict instance of AHHyperlinkScanner with a given NSAttributedString.+strictHyperlinkScannerWithAttributedString: Creates a strict instance of AHHyperlinkScanner with a given NSAttributedString.+isStringValidURI:usingStrict:fromIndex:withStatus: Returns a BOOL of the given string's validity. Instance Methods-nextURI Returns the next valid URI in the string as an AHMarkedHyperlink.-allURIs Returns an NSArray of all valid URIs in the scanner's string as AHMarkedHyperlinks.-linkifiedString Returns an attributed string of the original string with NSURLs attached to all URI substrings. If the class was instantiated with an attributed string, all original attributes are preserved. Other QuestionsWhat kinds of URLs will it match?
What kinds of URLs will it not matchWe allow simple domain names to be linked in non-strict mode, however we never match the following:
|
Sign in to add a comment