summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/plaintext.pm
blob: eaa2725b9aee5439bb8368727bc40853d2cca276 (plain)
  1. #!/usr/bin/perl
  2. # Plaintext as a wiki page type - links WikiLinks and URIs.
  3. #
  4. # Copyright (C) 2008 Gabriel McManus <gmcmanus@gmail.com>
  5. # Licensed under the GNU General Public License, version 2 or later
  6. package IkiWiki::Plugin::plaintext;
  7. use warnings;
  8. use strict;
  9. use IkiWiki 2.00;
  10. use HTML::Entities;
  11. require URI::Find;
  12. sub import {
  13. hook(type => "filter", id => "txt", call => \&filter);
  14. hook(type => "htmlize", id => "txt", call => \&htmlize);
  15. }
  16. # We use filter to convert raw text to HTML
  17. # (htmlize is called after other plugins insert HTML)
  18. sub filter (@) {
  19. my %params = @_;
  20. my $content = $params{content};
  21. if ($pagesources{$params{page}} =~ /.txt$/) {
  22. encode_entities($content);
  23. my $finder = URI::Find->new(
  24. sub {
  25. my($uri, $orig_uri) = @_;
  26. return qq|<a href="$uri">$orig_uri</a>|;
  27. });
  28. $finder->find(\$content);
  29. $content = "<pre>" . $content . "</pre>";
  30. }
  31. return $content;
  32. }
  33. # We need this to register the .txt file extension
  34. sub htmlize (@) {
  35. my %params=@_;
  36. return $params{content};
  37. }
  38. 1