irc.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 3 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, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('irc.pl', 'IRC Log Extension');
  18. our ($q, $bol, %RuleOrder, @MyRules);
  19. our ($IrcNickRegexp, $IrcLinkNick);
  20. push(@MyRules, \&IrcRule);
  21. $RuleOrder{\&IrcRule} = 200; # after HTML tags in Usemod Markup Extension.
  22. $IrcNickRegexp = qr{[]a-zA-Z^[;\\`_{}|][]^[;\\`_{}|a-zA-Z0-9-]*};
  23. $IrcLinkNick = 0;
  24. # This adds an extra <br> at the beginning. Alternatively, add it to
  25. # the last line, or only add it when required.
  26. sub IrcRule {
  27. if ($bol && m/\G(?:\[?(\d\d?:\d\d(?:am|pm)?)\]?)?\s*&lt;($IrcNickRegexp)&gt; ?/cg) {
  28. my ($time, $nick) = ($1, $2);
  29. my ($error) = ValidId($nick);
  30. # if we're in a dl, close the open dd but not the dl. (if we're
  31. # not in a dl, that closes all environments.) then open a dl
  32. # unless we're already in a dl. put the nick in a dt.
  33. my $html = CloseHtmlEnvironmentUntil('dd') . OpenHtmlEnvironment('dl', 1, 'irc')
  34. . AddHtmlEnvironment('dt');
  35. $html .= $q->span({-class=>'time'}, $time, ' ') if $time;
  36. if ($error or not $IrcLinkNick) {
  37. $html .= $q->b($nick);
  38. } else {
  39. $html .= GetPageOrEditLink($nick);
  40. }
  41. $html .= CloseHtmlEnvironment('dt') . AddHtmlEnvironment('dd');
  42. return $html;
  43. }
  44. return;
  45. }