ikiwiki/IkiWiki/Plugin/txt.pm

71 lines
1.5 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
2010-02-12 07:10:36 +01:00
section => "format",
},
}
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};
if (defined $pagesources{$params{page}} &&
$pagesources{$params{page}} =~ /\.txt$/) {
if ($pagesources{$params{page}} eq 'robots.txt' &&
$params{page} eq $params{destpage}) {
will_render($params{page}, 'robots.txt');
writefile('robots.txt', $config{destdir}, $content);
}
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