[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  New and improved Hyperlink_URL (Not an April Fools joke)
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

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] Refresh page


Posted by Sketch-The-Fox   (19 posts)  [Biography] 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>
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] 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!
[Go to top] top

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] 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
[Go to top] top

Posted by Mephator   Canada  (5 posts)  [Biography] 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?
[Go to top] 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.


6,021 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]