ikiwiki/IkiWiki/Plugin/txt.pm

47 lines
1021 B
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 2.00;
use HTML::Entities;
require URI::Find;
sub import {
2008-06-25 02:35:21 +02:00
hook(type => "filter", id => "txt", call => \&filter);
hook(type => "htmlize", id => "txt", call => \&htmlize);
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 ($pagesources{$params{page}} =~ /.txt$/) {
encode_entities($content);
my $finder = URI::Find->new(
sub {
my ($uri, $orig_uri) = @_;
return qq|<a href="$uri">$orig_uri</a>|;
});
$finder->find(\$content);
$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