Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Plugins ➜ New and improved Hyperlink_URL (Not an April Fools joke)

New and improved Hyperlink_URL (Not an April Fools joke)

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Sketch-The-Fox   (19 posts)  Bio
Date Sat 01 Apr 2006 05:32 PM (UTC)
Message
Worked on this for a while. It's about time I gave something back to the community. This version of Hyperlink_URL preserves colors, and can parse more than one hyperlink per line. Would it be worth putting up in the plugins page? Regardless of that, here it is.
<?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_URL" author="Sketch" id="520bc4f29806f7af0017985f" language="Lua" purpose="Makes URLs on a line into hyperlinks." date_written="2006-04-01" requires="3.72" version="1.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\.\?\/\%#@!&quot;&amp;_]+[/\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)

  hyperlinks = {}
  newstyle = {}
  i = 1
  hyperlinkcount = 0
  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 pairs (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>
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #1 on Tue 04 Apr 2006 11:04 AM (UTC)
Message
Hello.
This script rocks.
That is all.

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Thu 06 Apr 2006 10:37 PM (UTC)
Message
Very nice. Also supports multiple hyperlinks on the same line. I have added it to the plugins page.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 06 Apr 2006 10:54 PM (UTC)
Message
BTW - you know Lua has booleans? So rather than:


doingURL = 1


and then


if doingURL == 1 then 


You can write:


doingURL = true


and then


if doingURL then 


Just looks a bit neater. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Mephator   Canada  (5 posts)  Bio
Date Reply #4 on Sat 08 Nov 2008 06:12 PM (UTC)
Message
Sorry to raise this topic from the dead, but I'm trying to figure out how to change the color of the URL that is output but can't seem to get anything to work.

I thought that if I changed RGBColourToName(y.textcolour) to RGBColourToName(blue) that it would work, but I'm wrong.

Any help?
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


18,995 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.