Autolinker Class
Item Index
Properties
- htmlRegex!~YUIDOC_LINE~!!~YUIDOC_LINE~!A regular expression used to pull out HTML tags from a string.!~YUIDOC_LINE~!!~YUIDOC_LINE~!Capturing groups:!~YUIDOC_LINE~!!~YUIDOC_LINE~!1. If it is an end tag, this group will have the '/'.!~YUIDOC_LINE~!2. The tag name.
- htmlRegex!~YUIDOC_LINE~!!~YUIDOC_LINE~!A regular expression used to pull out HTML tags from a string.!~YUIDOC_LINE~!!~YUIDOC_LINE~!Capturing groups:!~YUIDOC_LINE~!!~YUIDOC_LINE~!1. If it is an end tag, this group will have the '/'.!~YUIDOC_LINE~!2. The tag name.
- matcherRegex!~YUIDOC_LINE~!!~YUIDOC_LINE~!The regular expression that matches URLs, email addresses, and Twitter handles.!~YUIDOC_LINE~!!~YUIDOC_LINE~!Capturing groups:!~YUIDOC_LINE~!!~YUIDOC_LINE~!1. Group that is used to determine if there is a Twitter handle match (i.e. @someTwitterUser). Simply check for its existence!~YUIDOC_LINE~! to determine if there is a Twitter handle match. The next couple of capturing groups give information about the Twitter !~YUIDOC_LINE~! handle match.!~YUIDOC_LINE~!2. The whitespace character before the @sign in a Twitter handle. This is needed because there are no lookbehinds in JS regular!~YUIDOC_LINE~! expressions, and can be used to reconstruct the original string in a replace().!~YUIDOC_LINE~!3. The Twitter handle itself in a Twitter match. If the match is '@someTwitterUser', the handle is 'someTwitterUser'.!~YUIDOC_LINE~!4. Group that matches an email address. Used to determine if the match is an email address, as well as holding the full address.!~YUIDOC_LINE~! Ex: 'me@my.com'!~YUIDOC_LINE~!5. Group that matches a URL in the input text. Ex: 'http://google.com', 'www.google.com', or just 'google.com'.!~YUIDOC_LINE~! This also includes a path, url parameters, or hash anchors. Ex: google.com/path/to/file?q1=1&q2=2#myAnchor
- prefixRegex!~YUIDOC_LINE~!!~YUIDOC_LINE~!A regular expression used to remove the 'http://' or 'https://' and/or the 'www.' from URLs.
- prefixRegex!~YUIDOC_LINE~!!~YUIDOC_LINE~!A regular expression used to remove the 'http://' or 'https://' and/or the 'www.' from URLs.
Methods
link
-
html
-
[options]
Automatically links URLs, email addresses, and Twitter handles found in the given chunk of HTML. Does not link URLs found within HTML tags.
For instance, if given the text: You should go to http://www.yahoo.com
, then the result
will be You should go to <a href="http://www.yahoo.com">http://www.yahoo.com</a>
Parameters:
-
html
StringThe HTML text to link URLs within.
-
[options]
Object optionalAny options for the autolinking, specified in an object. It may have the following properties:
-
[newWindow=true]
Boolean optionalTrue if the links should open in a new window, false otherwise.
-
[stripPrefix=true]
Boolean optionalTrue if 'http://' or 'https://' and/or the 'www.' should be stripped from the beginning of links, false otherwise.
-
[truncate]
Number optionalA number for how many characters long URLs/emails/twitter handles should be truncated to inside the text of a link. If the URL/email/twitter is over the number of characters, it will be truncated to this length by adding a two period ellipsis ('..') into the middle of the string. Ex: a url like 'http://www.yahoo.com/some/long/path/to/a/file' truncated to 25 characters might look like this: 'http://www...th/to/a/file'
-
[twitter=true]
Boolean optionalTrue if Twitter handles ("@example") should be automatically linked.
-
[email=true]
Boolean optionalTrue if email addresses should be automatically linked.
-
[urls=true]
Boolean optionalTrue if miscellaneous URLs should be automatically linked.
-
Returns:
The HTML text, with URLs automatically linked
link
-
html
-
[options]
Automatically links URLs, email addresses, and Twitter handles found in the given chunk of HTML. Does not link URLs found within HTML tags.
For instance, if given the text: You should go to http://www.yahoo.com
, then the result
will be You should go to <a href="http://www.yahoo.com">http://www.yahoo.com</a>
Parameters:
-
html
StringThe HTML text to link URLs within.
-
[options]
Object optionalAny options for the autolinking, specified in an object. It may have the following properties:
-
[newWindow=true]
Boolean optionalTrue if the links should open in a new window, false otherwise.
-
[stripPrefix=true]
Boolean optionalTrue if 'http://' or 'https://' and/or the 'www.' should be stripped from the beginning of links, false otherwise.
-
[truncate]
Number optionalA number for how many characters long URLs/emails/twitter handles should be truncated to inside the text of a link. If the URL/email/twitter is over the number of characters, it will be truncated to this length by adding a two period ellipsis ('..') into the middle of the string. Ex: a url like 'http://www.yahoo.com/some/long/path/to/a/file' truncated to 25 characters might look like this: 'http://www...th/to/a/file'
-
[twitter=true]
Boolean optionalTrue if Twitter handles ("@example") should be automatically linked.
-
[email=true]
Boolean optionalTrue if email addresses should be automatically linked.
-
[urls=true]
Boolean optionalTrue if miscellaneous URLs should be automatically linked.
-
Returns:
The HTML text, with URLs automatically linked