Posted by
| Nick Gammon
Australia (23,122 posts) Bio
Forum Administrator |
Message
| I tried your test line and it didn't crash, and hyperlinked it OK. Maybe you are using a different version? Try this:
|
To save and install the Hyperlink_URL2 plugin do this:
- Copy between the lines below (to the Clipboard)
- Open a text editor (such as Notepad) and paste the plugin into it
- Save to disk on your PC, preferably in your plugins directory, as Hyperlink_URL2.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file Hyperlink_URL2.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
<?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"
author="Sketch"
id="520bc4f29806f7af0017985f"
language="Lua"
purpose="Makes URLs on a line into hyperlinks."
date_written="2006-04-01"
date_modified="2009-01-28"
requires="3.72"
version="2.0">
<description trim="y">
<![CDATA[
Detects text starting with HTTP:xxx and makes that part into a hyperlink.
Limits: HTTP:// and the following character must be the same color
]]>
</description>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="(.*)((https?|mailto)://(?:[\w\d\.\?\/\%#@!"&_]+[/\w\d#]))(.*)$"
omit_from_output="y"
ignore_case="y"
regexp="y"
script="OnHyperlink"
sequence="100"
>
</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 **** --
cut = string.find(styles[i].text, "([hHtTpPsSmMaAiIlLoO]+://[%S]*[%w#/])")
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]
, RGBColourToName(y.textcolour), RGBColourToName(y.backcolour), 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>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|