]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/format.pm
move to correct location
[ikiwiki.git] / IkiWiki / Plugin / format.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::format;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
7
8 sub import {
9         hook(type => "preprocess", id => "format", call => \&preprocess);
10         hook(type => "getsetup",   id => "format", call => \&getsetup);
11 }
12
13 sub getsetup () {
14         return
15                 plugin => {
16                         safe => 1,
17                         rebuild => undef,
18                 },
19 }
20
21 sub preprocess (@) {
22         my %params=@_;
23         my $format=shift;
24         shift;
25         my $text=IkiWiki::preprocess($params{page}, $params{destpage}, shift);
26         shift;
27
28         if (! defined $format || ! defined $text) {
29                 error(gettext("must specify format and text"));
30         }
31         elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
32                 return IkiWiki::htmlize($params{page}, $params{destpage},
33                                         $format, $text);
34         }
35         else {
36                 # Other plugins can register htmlizefallback
37                 # hooks to add support for page types
38                 # not suitable for htmlize. Try them until
39                 # one succeeds.
40                 my $ret;
41                 IkiWiki::run_hooks(htmlizefallback => sub {
42                         $ret=shift->($format, $text)
43                                 unless defined $ret;
44                 });
45                 return $ret if defined $ret;
46
47                 error(sprintf(gettext("unsupported page format %s"), $format));
48         }
49 }
50
51 1