<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, 1 April 2006, 12:29 PM -->
<!-- MuClient version 3.73 -->
<muclient>
<plugin
name="Hyperlink_URL2(SVD)"
author="Sketch_and_ThumpieBunnyEve"
id="520bc4f29806f7af003d175d"
language="Lua"
purpose="Makes URLs on a line into hyperlinks."
date_written="2006-04-01"
date_modified="2009-05-18"
requires="3.72"
version="2.0">
<description trim="y">
<![CDATA[
Hyperlink_URL2(SVD) (S.cripting V.ariable D.ependent)
Detects text starting with HTTP:xxx and makes that part into a hyperlink.
Limits: HTTP:// and the following character must be the same color
You will need to add 2 values to your WorldProperties-Scripting-Variables section.
All values indicated must be in Hexadecimal.
If you are new to Hexadecimal color values, please visit the following link,
http://en.wikipedia.org/wiki/WebColor#HTML_color_names
I recommend the following values, for link color.
name: urlbackcolour
content: #000000
name: urltextcolour
content: #0080ff
]]>
</description>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="(.*)(((https?|mailto|ftp)://(?:[\w\d\.\?\/\%#@!"&_]+[/\w\d#]))|([wW]{3}+\.))(.*)$"
omit_from_output="y"
ignore_case="y"
regexp="y"
script="OnHyperlink"
sequence="1"
>
</trigger>
</triggers>
<!-- Script -->
<script>
<![CDATA[
function OnHyperlink (name, line, wildcards, styles)
local hyperlinks = {}
local newstyle = {}
local i = 1
local hyperlinkcount = 0
local doingURL = 0
while i <= table.getn(styles) do -- Doesn't use pairs() because of problems with field-injection.
if doingURL == 0 then
-- **** Not a URL **** --
local vader = styles[i].text:lower()
cut = vader:find("ftp://") or vader:find("http://") or vader:find("mailto://") or vader:find("[/w]-www\.")
if cut == nil then -- If there's nothing to cut, copy the whole line
table.insert(newstyle, {textcolour = styles[i].textcolour
,backcolour = styles[i].backcolour
,style = styles[i].style
,text = styles[i].text})
else
table.insert(newstyle, {textcolour = styles[i].textcolour
,backcolour = styles[i].backcolour
,style = styles[i].style
,text = string.sub(styles[i].text, 1, cut - 1)})
table.insert(styles, i + 1, {textcolour = styles[i].textcolour
,backcolour = styles[i].backcolour
,style = styles[i].style
,text = string.sub(styles[i].text, cut)})
doingURL = 1
hyperlinkcount = hyperlinkcount + 1
end -- if
else -- **** IS a URL **** --
-- Search for a URL. If the string is completely a URL...
-- Jump to the next table field. And keep doing such.
cut, length, temp = string.find(styles[i].text, "^([%S]*[%w#/])")
if cut ~= nil then
if hyperlinks[hyperlinkcount] ~= nil then
hyperlinks[hyperlinkcount] = hyperlinks[hyperlinkcount] .. temp
else
hyperlinks[hyperlinkcount] = temp
end -- if
table.insert(newstyle, {textcolour = styles[i].textcolour
,backcolour = styles[i].backcolour
,style = styles[i].style
,text = string.sub(styles[i].text, 1, length)
,hypernumber = hyperlinkcount})
styles[i].text = string.sub(styles[i].text, length + 1)
if styles[i].text ~= "" then
i = i - 1 -- The first hyperlink was cut, so scan the same field for more.
doingURL = 0
else
doingURL = 1
end
else
doingURL = 0
i = i - 1
end -- if (cut)
end -- if (doingURL)
i = i + 1
end -- while
for x, y in ipairs (newstyle) do -- x is the style number, y is the style-data table.
NoteStyle (y.style)
if y.hypernumber ~= nil then
Hyperlink(hyperlinks[y.hypernumber], y.text, "Go to " .. hyperlinks[y.hypernumber]
, GetPluginVariable ("", "urltextcolour"), GetPluginVariable ("", "urlbackcolour"), 1)
else
ColourTell (RGBColourToName(y.textcolour), RGBColourToName(y.backcolour), y.text)
end
end -- while
Note ("") -- Insert a true newline at the end of the string.
end -- of hyperlink
]]>
</script>
</muclient>
|