Bonjour encore Patrick

I realised that my simplistic function had an logic error so that it 
only would have processed the first url it came across. I've updated it 
now.

highlight-links: func [
     {Wraps an <a href> tag around http urls in a string.}
     text [string!]
     "The string containing http urls."
     /local
       url-end
          "Used to workout where the url ends"
][
    while [find text "http://";]
    [
       text: find text "http://";
                                                         ;; find char 
after url
       url-end: copy find/tail text "http:"
       until
       [
          url-end: next url-end
          any
          [
             (url-end = "")
             (#" " = first url-end)
             (#"," = first url-end)
             (#":" = first url-end)
             (#";" = first url-end)
          ]
       ]
                                                 ;; insert the <a> tag
       either url-end = ""                          ;; url is at end of 
text
       [
          insert text rejoin
          [
             {<a href="}
             copy text
             {">}
          ]
          insert text: tail text "</a>"
       ][                                             ;; text after url
          url-end: first url-end
          insert text rejoin
          [
             {<a href="}
             copy/part text find text url-end
             {">}
          ]
          text: find/tail text {">}      ;; skip over insert
          text: find text url-end
          insert text "</a>"
       ]
     ]
     text: head text
]

Regards
Peter

-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to