Last active
March 23, 2020 00:51
-
-
Save chrisdpeters/1840044 to your computer and use it in GitHub Desktop.
Using Extra CFC Attributes for Documentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffunction | |
name="autoLink" | |
returntype="string" | |
access="public" | |
output="false" | |
hint="Turns all URLs and e-mail addresses into clickable links." | |
examples=' | |
##autoLink("Download Wheels from http://cfwheels.org/download")## | |
-> Download Wheels from <a href="http://cfwheels.org/download">http://cfwheels.org/download</a> | |
##autoLink("Email us at info@cfwheels.org")## | |
-> Email us at <a href="mailto:info@cfwheels.org">info@cfwheels.org</a> | |
' | |
categories="view-helper,text" | |
functions="excerpt,highlight,simpleFormat,titleize,truncate" | |
> | |
<cfargument name="text" type="string" required="true" hint="The text to create links in."> | |
<cfargument name="link" type="string" required="false" default="all" hint="Whether to link URLs, email addresses or both. Possible values are: `all` (default), `URLs` and `emailAddresses`."> | |
<cfscript> | |
var loc = {}; | |
loc.urlRegex = "(?ix)([^(url=)|(href=)'""])(((https?)://([^:]+\:[^@]*@)?)([\d\w\-]+\.)?[\w\d\-\.]+\.(com|net|org|info|biz|tv|co\.uk|de|ro|it)(( / [\w\d\.\-@%\\\/:]* )+)?(\?[\w\d\?%,\.\/\##!@:=\+~_\-&]*(?<![\.]))?)"; | |
loc.mailRegex = "(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))"; | |
loc.returnValue = arguments.text; | |
if (arguments.link != "emailAddresses") | |
loc.returnValue = loc.returnValue.ReplaceAll(loc.urlRegex, "$1<a href=""$2"">$2</a>"); | |
if (arguments.link != "URLs") | |
loc.returnValue = REReplaceNoCase(loc.returnValue, loc.mailRegex, "<a href=""mailto:\1"">\1</a>", "all"); | |
</cfscript> | |
<cfreturn loc.returnValue> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment