Convert list of urls to hotlinks

Convert list of urls to hotlinks

2

    Feb 15, 2009#1

    is there a macro available that will convert lists of urls like

    http://www.abc.com/widgets/1.html
    http://www.abc.com/widgets/2.html
    http://www.abc.com/widgets/3.html
    ..
    http://www.abc.com/widgets/99.html

    to
    <a href="http://www.abc.com/widgets/1.html">http://www.abc.com/widgets/1.html</a>
    <a href="http://www.abc.com/widgets/2.html">http://www.abc.com/widgets/2.html</a>
    <a href="http://www.abc.com/widgets/2.html">http://www.abc.com/widgets/3.html</a>
    <a href="http://www.abc.com/widgets/3.html">http://www.abc.com/widgets/4.html</a>

    236
    MasterMaster
    236

      Feb 15, 2009#2

      That's not really a job for a macro, more for a regular expression. Take note of this article that explains the difficulty in solving this problem, though: Detecting URLs in a block of text

      In your case, I would recommend a Perl regular expression replace action as follows:

      Search string:

      \b((https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|])

      Replace all with

      <a href="\1">\1</a>

      This will only find URLs that start with http(s)/ftp/file, not "simplified" URLs that start with www; it also won't find URLs that end in parentheses and some other corner cases. This is just a starting point, so if this works for your real-life data, fine. If not, check out the article linked above whether you need a different pattern.

      2

        Feb 15, 2009#3

        Thank you kindly. This is awesome.