]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/format.pm
Merge branch 'autotag'
[git.ikiwiki.info.git] / IkiWiki / Plugin / format.pm
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);
11 }
13 sub getsetup () {
14         return
15                 plugin => {
16                         safe => 1,
17                         rebuild => undef,
18                         section => "widget",
19                 },
20 }
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"));
31         }
32         elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
33                 return IkiWiki::htmlize($params{page}, $params{destpage},
34                                         $format, $text);
35         }
36         else {
37                 # Other plugins can register htmlizefallback
38                 # hooks to add support for page types
39                 # not suitable for htmlize. Try them until
40                 # one succeeds.
41                 my $ret;
42                 IkiWiki::run_hooks(htmlizefallback => sub {
43                         $ret=shift->($format, $text)
44                                 unless defined $ret;
45                 });
46                 return $ret if defined $ret;
48                 error(sprintf(gettext("unsupported page format %s"), $format));
49         }
50 }
52 1