Lasso Soft Inc. > Home

[LEAP_makeLink]

LinkLEAP_makeLink
AuthorJonathan Guthrie
CategoryString
Version9.x
LicensePublic Domain
Posted20 Dec 2010
Updated20 Dec 2010
More by this author...

Description

Parses a string for links to make clickable links.

Based on the RegExp published at http://daringfireball.net/2010/07/improved_regex_for_matching_urls

 

Accepts an optional keyword parameter "newWindow" that inserts _target="blank" if true. The default value is false.

Sample Usage

LEAP_makeLink('Visit http://www.lassosoft.com/ every day!') 
LEAP_makeLink('Visit http://www.lassosoft.com/ every day!',-newWindow=true) 

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define LEAP_makeLink(x::string,-newWindow::boolean=false) => {
	// ref http://daringfireball.net/2010/07/improved_regex_for_matching_urls
	#x = string(string_replaceregexp(
		#x, 
		-find='(\\W|^)((?:https?://(?:[a-z0-9.\\-]+[.])+[a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))*(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\]\\[{};:\'".,<>?«»])?)',
		-replace='\\1\\2'
	))
	if(#newWindow) => {
		#x->replace('|XX|',' target="_blank"')
	else
		#x->replace('|XX|','')
	}
	return #x
}

Comments

16 May 2014, ram marr

Thank you

Thanks for this it saved me time, make sure you copy the complete code or it will not work, i erased mine also

 

 

 

Robin  

19 Sep 2011, Bryce Smith

Simplify the target="_blank"

this code saved me a lot of time.









SEO Services Providence, RI

27 Jan 2011, Brad Lindsay

Simplify the target="_blank"

Hmmm. It erased my code...

In place of the |XX| in the -replace= you can concatenate in the following:

(#newWindow ? 'target="blank"' | '')

27 Jan 2011, Brad Lindsay

Simplify the target="_blank"

You can simplify the code by not using the |XX| and instead put the logic for it there. In other words, the -replace= could look like this:

-replace='\\1\\2'

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft