response
[ikiwiki.git] / IkiWiki / Plugin / format.pm
blobb596bc0a10343b91cf7287f5b5fa06a81084b055
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::format;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
8 sub import {
9 hook(type => "preprocess", id => "format", call => \&preprocess);
10 hook(type => "getsetup", id => "format", call => \&getsetup);
13 sub getsetup () {
14 return
15 plugin => {
16 safe => 1,
17 rebuild => undef,
18 section => "widget",
22 sub preprocess (@) {
23 my %params=@_;
24 my $format=shift;
25 shift;
26 my $text=IkiWiki::preprocess($params{page}, $params{destpage}, shift);
27 shift;
29 if (! defined $format || ! defined $text) {
30 error(gettext("must specify format and text"));
33 # Other plugins can register htmlizeformat hooks to add support
34 # for page types not suitable for htmlize, or that need special
35 # processing when included via format. Try them until one succeeds.
36 my $ret;
37 IkiWiki::run_hooks(htmlizeformat => sub {
38 $ret=shift->($format, $text)
39 unless defined $ret;
40 });
42 if (defined $ret) {
43 return $ret;
45 elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
46 return IkiWiki::htmlize($params{page}, $params{destpage},
47 $format, $text);
49 else {
50 error(sprintf(gettext("unsupported page format %s"), $format));