Lasso Soft Inc. > Home

[text_to_url]

Linktext_to_url
AuthorAsle Benoni
CategoryString
Version8.x
LicensePublic Domain
Posted21 Feb 2006
Updated10 Jul 2008
More by this author...

Description

Lasso8 version of a simple tag to make URL and MAILTO: links from a text input or field.

Mail addresses are converted to <a href="mailto:foo@foo.com">foo@foo.com</a>. It searches for any links beginning with "www..." and converts them to <a href=> links. A link without "www" will also be clickable as long as it starts with "http://". Of course it cannot decide if a text like "blueworld.com" is a URL. The tag should guess all kinds of weird URLS.

If the text includes i.e. <a href="http://bw.com">Click here</a> links it does not treat them since these are hard coded already and you don't want to change them. It only treats obvious links that are not already clickable.

Option to choose whether or not to show "http://" in the link text.

Sample Usage

 Usage:
   text_to_url:'Please visit us at www.sample.com'
      -> Please visit us at http://www.sample.com
    
    text_to_url:'Please visit us at http://sample.com'
      -> Please visit us at http://sample.com
    
    text_to_url:'Please contact us at support@sample.com'
      -> Please visit us at suppport@sample.com

If you want to leave out the "http://" in the link text you must change the value of local:'linktext'

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_tag: 'text_to_url', -Required='Field', -optional='target';
    /*
    #############################################################################################################
    ## Custom_tag: [text_to_url]
    ## Version: 1.2.2
    ## Date: 6-8-2004 - updated 11-2005 (03-2007 bugfix) for Lasso 8 by suggestion from Johan Solve
    ## Author: Asle Benoni - asle@benoni.no || use it as you like but at your own risk ;-)
    ## Function: Takes a textinput containing URLs (HTTP, HTTPS, FTP) and email adresses and converts them to clickable links
    ## Platform: Lasso 8.5, 8 7 and Lasso 6.
    ## Availability: FREE - but I would be glad to hear if you are using it or have suggestions/requests for changes
    ## -> and if you keep the author information here ;-)
    ##
    ## A simple tag to make URL and MAILTO links from a text input or field.
    ## It searches for any links beginning with "www..." and converts them to  links.
    ## A link without "www" will also be clickable as long as there it starts with "http://"
    ## Of course it cannot decide if a text like "blueworld.com" is a URL.
    ## The tag should guess all kinds of weird URLS
    ## If the text includes i.ex. Click here links it does not treat them since
    ## these are hardcoded already and you don`t want to change them. It only treats obvious links that
    ## are not already clickable.
    ##
    ## Usage:
    ## text_to_url:'Please visit us at www.sample.com'
    ## -> Please visit us at http://www.sample.com
    ##
    ## text_to_url:'Please visit us at http://sample.com'
    ## -> Please visit us at http://sample.com
    ##
    ## text_to_url:'Please contact us at support@sample.com'
    ## -> Please visit us at suppport@sample.com
    ##
    ## If you want to leave out the "http://" in the link text you must change the value of local:'linktext'
    ##
    #############################################################################################################
    */

    local:'urltext'= '';
    local:'linktext'= '\\1';  // Change this value to '\\3' if you DO NOT want the link text to show a leading 'http://'

    // First we change all "www.xx.xx" to "http://...."
    #urltext = (String_ReplaceRegExp: #Field,
        -Find='((? Visit us "
    #urltext=(String_ReplaceRegExp: #urltext,
        -Find='((?)(https?://|ftp://)((([A-Za-z0-9$_.+!*(),;/?:@&~=-]+)|%[A-Fa-f0-9]{2})+(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?))',
        -Replace=''+ #linktext +'',-ignorecase);

    // Create email-links from found email
    #urltext = (String_ReplaceRegExp: #urltext,
        -Find='([a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4})',
        -Replace='\\1',-ignorecase);

    #urltext = (String_Replace: -Find='\n', -Replace='
\n', #urltext, -EncodeNone); return: @#urltext; /define_tag;

Related Tags

Comments

10 Jul 2008, Asle Benoni

Small fix

Small fix for difficult URLs. Working on a better rewrite for URL regex replacement.

25 Aug 2007, Stefan Straakenbroek

Little change

Changed the 'fix' "*" sign to "+" because it went wrong when url's has some "%" signs in it.

15 Aug 2007, Stefan Straakenbroek

Bug found with converting a url

Hello Asle Benoni,

Thanx for the great tags. Works great but get some wierd error when i tried to convert this text to an url with your tag.

http://www.buzzle.com/articles/social-book-marking-traffic-secrets-using-social-book-marking-to-promote-your-website.html

When i changed you regExp to:

-Find='((?)(https?://|ftp://)((([A-Za-z0-9$_.+!*(),;/?:@&~=-]*)|%[A-Fa-f0-9]{2})+(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?))',

It seems to working fine. I add a "*" sign between the "]" and ")" in ",;/?:@&~=-])|%" so you get ",;/?:@&~=-]*)|%"

Don't know if it is the right solution, but it stops crashing the server here :)

Regards,

Stefan

30 Mar 2007, Asle Benoni

Updated to work with Encode_Break.

There was an issue where a URL would not be processed if it was close to a
tags or adding them with Encode_Break woul break the process of the that URL. i.ex.
www.lassosoft.com would be ignored while
[space]www.lassosoft would work. Any tag can now be close to a URL.

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