[LEAP_makeLink]

Description

Link: [LEAP_makeLink]
Author: Jonathan Guthrie
Category: String
Version: 9.x
License: Public Domain
Posted: Dec. 20, 2010
Updated: Dec. 20, 2010
More by this author...

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.

Parameters

none


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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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<a href="\\2"|XX|>\\2</a>'
	))
	if(#newWindow) => {
		#x->replace('|XX|',' target="_blank"')
	else
		#x->replace('|XX|','')
	}
	return #x
}

 

Comments

09/19/2011, ram marr
Simplify the target="_blank"
this code saved me a lot of time.
SEO Services Providence, RI
01/27/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"' | '')
01/27/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'
Email:


Password:



Newest

Most Popular

Support tagSwap.net