ikiwiki/IkiWiki/Plugin/txt.pm

63 lines
1.3 KiB
Perl
Raw Normal View History

2008-06-25 02:33:03 +02:00
#!/usr/bin/perl
2008-06-25 02:33:41 +02:00
# .txt as a wiki page type - links WikiLinks and URIs.
2008-06-25 02:33:03 +02:00
#
# Copyright (C) 2008 Gabriel McManus <gmcmanus@gmail.com>
# Licensed under the GNU General Public License, version 2 or later
2008-06-25 02:33:41 +02:00
package IkiWiki::Plugin::txt;
2008-06-25 02:33:03 +02:00
use warnings;
use strict;
use IkiWiki 3.00;
2008-06-25 02:33:03 +02:00
use HTML::Entities;
my $findurl=0;
2008-06-25 02:33:03 +02:00
sub import {
hook(type => "getsetup", id => "txt", call => \&getsetup);
hook(type => "filter", id => "txt", call => \&filter);
2008-06-25 02:35:21 +02:00
hook(type => "htmlize", id => "txt", call => \&htmlize);
eval q{use URI::Find};
if (! $@) {
$findurl=1;
}
2008-06-25 02:33:03 +02:00
}
sub getsetup () {
return
plugin => {
safe => 1,
rebuild => 1, # format plugin
},
}
2008-06-25 02:33:03 +02:00
# We use filter to convert raw text to HTML
# (htmlize is called after other plugins insert HTML)
sub filter (@) {
2008-06-25 02:35:21 +02:00
my %params = @_;
my $content = $params{content};
2008-06-25 02:47:15 +02:00
if (defined $pagesources{$params{page}} && $pagesources{$params{page}} =~ /\.txt$/) {
encode_entities($content, "<>&");
if ($findurl) {
my $finder = URI::Find->new(sub {
my ($uri, $orig_uri) = @_;
return qq|<a href="$uri">$orig_uri</a>|;
});
$finder->find(\$content);
}
2008-06-25 02:35:21 +02:00
$content = "<pre>" . $content . "</pre>";
}
return $content;
2008-06-25 02:33:03 +02:00
}
# We need this to register the .txt file extension
sub htmlize (@) {
2008-06-25 02:35:21 +02:00
my %params=@_;
return $params{content};
2008-06-25 02:33:03 +02:00
}
1