Switch to edit mode.
Name(s): munge_by_autohyperlink1: "munge_by_autohyperlink(text) => munged text."
2: "text may be a list or a string. The return value will have strings like 'www.moo.ca' turned into hyperlinks to http://www.moo.ca. e-mail addresses will become mailto: hyperlink, and full URLs will also become hyperlinks to those urls. The visible text will stay the same."
3: "Regexs taken from MOOzilla. This is the same autohyperlinking it does."
4: {txt} = args
5: urlRegex = "%(%(http%|https%|gopher%|ftp%|telnet%|nntp%|news%|snews%)://%([-a-z0-9]+%.%)*[-a-z0-9]+%(:[0-9]+%)?/?[^ '`\\\"]*%)"
6: wwwRegex = "%(www%.%([-a-z0-9]+%.%)+[a-z]+%(:[0-9]+%)?/?[^ '`\\\"]*%)"
7: mailRegex = "%(%(mailto:%)?%([^@ \"'`{}()<>;,]+%)@[-a-z0-9]+%(%.[-a-z0-9]+%)+%)"
8: txt = toliteral(txt)
9: output = ""
10: mail = www = url = 0
11: while ((match = match(txt, urlRegex)) && (url = 1) || ((match = match(txt, wwwRegex)) && (www = 1)) || ((match = match(txt, mailRegex)) && (mail = 1)))
12: output = output + txt[1..match[1] - 1]
13: if (url)
14: link = txt[match[3][1][1]..match[3][1][2]]
15: elseif (www)
16: link = "http://" + txt[match[3][1][1]..match[3][1][2]]
17: elseif (mail)
18: email = txt[match[3][1][1]..match[3][1][2]]
19: if (index(email, "mailto:") != 1)
20: email = "mailto:" + email
21: endif
22: link = email
23: endif
24: output = output + tostr("<a href=\\\"", link, "\\\">", txt[match[3][1][1]..match[3][1][2]], "</a>")
25: txt = txt[match[2] + 1..$]
26: mail = www = url = 0
27: endwhile
28: output = output + txt
29: output = $su:to_value(output)
30: if (output[1])
31: return output[2]
32: else
33: raise(E_NONE, "error in munge_by_autohyperlink...")
34: endif
35: "Last modified by Lao-Tzu (#8084) on Sun Aug 11 06:36:52 2002 MDT."