[text_to_url]

Description

Link: [text_to_url]
Author: Asle Benoni
Category: String
Version: 8.x
License: Public Domain
Posted: Feb. 21, 2006
Updated: Jul. 10, 2008
More by this author...
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.

Parameters

-Field string, required The string to convert
-target string, optional Target name of link. Default is same window

Sample Usage

Usage:
   text_to_url:'Please visit us at www.sample.com'
      -> Please visit us at <a href="http://www.sample.com">http://www.sample.com</a>
    
    text_to_url:'Please visit us at http://sample.com'
      -> Please visit us at <a href="http://sample.com">http://sample.com</a>
    
    text_to_url:'Please contact us at support@sample.com'
      -> Please visit us at <a href="mailto:support@sample.com">suppport@sample.com</a>

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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 <a href> 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. <a href="http://bw.com">Click here</a> 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 <a href="http://www.sample.com">http://www.sample.com</a>
    ##
    ## text_to_url:'Please visit us at http://sample.com'
    ## -> Please visit us at <a href="http://sample.com">http://sample.com</a>
    ##
    ## text_to_url:'Please contact us at support@sample.com'
    ## -> Please visit us at <a href="mailto:support@sample.com">suppport@sample.com</a>
    ##
    ## 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='((?<!://)www\\.)',
        -Replace='http://\\1',-ignorecase);


    // Then we change http://.... into clickable URLs (but NOT those already hardcoded
    // i.e. "<a href="http://sample.com"> Visit us </a>"
    #urltext=(String_ReplaceRegExp: #urltext,
        -Find='((?<!"|a>)(https?://|ftp://)((([A-Za-z0-9$_.+!*(),;/?:@&~=-]+)|%[A-Fa-f0-9]{2})+(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?))',
        -Replace='<a href=\"\\1\"'
            + ((local: 'target') !='' ? ' target="' + #target + '"')
            + '>'+ #linktext +'</a>',-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='<a href=\"mailto:\\1\">\\1</a>',-ignorecase);

    #urltext = (String_Replace: -Find='\n', -Replace='<br>\n', #urltext, -EncodeNone);

    return: @#urltext;

/define_tag;

 

Related Tags



Comments

07/10/2008, Asle Benoni
Small fix
Small fix for difficult URLs. Working on a better rewrite for URL regex replacement.
08/25/2007, Stefan Straakenbroek
Little change
Changed the 'fix' "*" sign to "+" because it went wrong when url's has some "%" signs in it.
08/15/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
03/30/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.
Email:


Password:



Newest

Most Popular