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,
|
2010-02-12 12:35:52 +01:00
|
|
|
section => "widget",
|
2010-02-06 22:25:39 +01:00
|
|
|
},
|
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"));
|
|
|
|
}
|
2010-10-26 04:37:34 +02:00
|
|
|
|
|
|
|
# Other plugins can register htmlizeformat hooks to add support
|
|
|
|
# for page types not suitable for htmlize, or that need special
|
|
|
|
# processing when included via format. Try them until one succeeds.
|
|
|
|
my $ret;
|
|
|
|
IkiWiki::run_hooks(htmlizeformat => sub {
|
|
|
|
$ret=shift->($format, $text)
|
|
|
|
unless defined $ret;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (defined $ret) {
|
|
|
|
return $ret;
|
|
|
|
}
|
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 {
|
|
|
|
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
|