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;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2008-06-25 02:33:03 +02:00
|
|
|
use HTML::Entities;
|
2008-06-25 02:38:41 +02:00
|
|
|
|
|
|
|
my $findurl=0;
|
2008-06-25 02:33:03 +02:00
|
|
|
|
|
|
|
sub import {
|
2008-08-04 01:35:35 +02:00
|
|
|
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);
|
2008-06-25 02:38:41 +02:00
|
|
|
|
|
|
|
eval q{use URI::Find};
|
|
|
|
if (! $@) {
|
|
|
|
$findurl=1;
|
|
|
|
}
|
2008-06-25 02:33:03 +02:00
|
|
|
}
|
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-04 01:35:35 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1, # format plugin
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-04 01:35:35 +02:00
|
|
|
|
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$/) {
|
2008-11-07 02:49:18 +01:00
|
|
|
encode_entities($content, "<>&");
|
2008-06-25 02:38:41 +02:00
|
|
|
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
|