2008-10-31 21:42:20 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::format;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2008-10-31 21:42:20 +01:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-10-31 21:42:20 +01:00
|
|
|
hook(type => "preprocess", id => "format", call => \&preprocess);
|
2010-02-06 22:25:39 +01:00
|
|
|
hook(type => "getsetup", id => "format", call => \&getsetup);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getsetup () {
|
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => undef,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-10-31 21:42:20 +01:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub preprocess (@) {
|
2008-10-31 21:42:20 +01:00
|
|
|
my %params=@_;
|
2009-05-23 11:17:26 +02:00
|
|
|
my $format=shift;
|
|
|
|
shift;
|
|
|
|
my $text=IkiWiki::preprocess($params{page}, $params{destpage}, shift);
|
|
|
|
shift;
|
2008-10-31 21:42:20 +01:00
|
|
|
|
|
|
|
if (! defined $format || ! defined $text) {
|
|
|
|
error(gettext("must specify format and text"));
|
|
|
|
}
|
2009-05-23 11:17:26 +02:00
|
|
|
elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
|
|
|
|
return IkiWiki::htmlize($params{page}, $params{destpage},
|
|
|
|
$format, $text);
|
2008-10-31 21:42:20 +01:00
|
|
|
}
|
2009-05-23 11:17:26 +02:00
|
|
|
else {
|
|
|
|
# Other plugins can register htmlizefallback
|
|
|
|
# hooks to add support for page types
|
|
|
|
# not suitable for htmlize. Try them until
|
|
|
|
# one succeeds.
|
|
|
|
my $ret;
|
|
|
|
IkiWiki::run_hooks(htmlizefallback => sub {
|
|
|
|
$ret=shift->($format, $text)
|
|
|
|
unless defined $ret;
|
|
|
|
});
|
|
|
|
return $ret if defined $ret;
|
2008-10-31 21:42:20 +01:00
|
|
|
|
2009-05-23 11:17:26 +02:00
|
|
|
error(sprintf(gettext("unsupported page format %s"), $format));
|
|
|
|
}
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-10-31 21:42:20 +01:00
|
|
|
|
|
|
|
1
|