irc.pl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the
  15. # Free Software Foundation, Inc.
  16. # 59 Temple Place, Suite 330
  17. # Boston, MA 02111-1307 USA
  18. use strict;
  19. use v5.10;
  20. AddModuleDescription('irc.pl', 'IRC Log Extension');
  21. our ($q, $bol, %RuleOrder, @MyRules);
  22. our ($IrcNickRegexp, $IrcLinkNick);
  23. push(@MyRules, \&IrcRule);
  24. $RuleOrder{\&IrcRule} = 200; # after HTML tags in Usemod Markup Extension.
  25. $IrcNickRegexp = qr{[]a-zA-Z^[;\\`_{}|][]^[;\\`_{}|a-zA-Z0-9-]*};
  26. $IrcLinkNick = 0;
  27. # This adds an extra <br> at the beginning. Alternatively, add it to
  28. # the last line, or only add it when required.
  29. sub IrcRule {
  30. if ($bol && m/\G(?:\[?(\d\d?:\d\d(?:am|pm)?)\]?)?\s*&lt;($IrcNickRegexp)&gt; ?/cg) {
  31. my ($time, $nick) = ($1, $2);
  32. my ($error) = ValidId($nick);
  33. # if we're in a dl, close the open dd but not the dl. (if we're
  34. # not in a dl, that closes all environments.) then open a dl
  35. # unless we're already in a dl. put the nick in a dt.
  36. my $html = CloseHtmlEnvironmentUntil('dd') . OpenHtmlEnvironment('dl', 1, 'irc')
  37. . AddHtmlEnvironment('dt');
  38. $html .= $q->span({-class=>'time'}, $time, ' ') if $time;
  39. if ($error or not $IrcLinkNick) {
  40. $html .= $q->b($nick);
  41. } else {
  42. $html .= GetPageOrEditLink($nick);
  43. }
  44. $html .= CloseHtmlEnvironment('dt') . AddHtmlEnvironment('dd');
  45. return $html;
  46. }
  47. return;
  48. }