]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/format.pm
Add ACTIONS variable to page.tmpl, which allows plugins to add arbitrary links to...
[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                         section => "widget",
19                 },
20 }
21
22 sub preprocess (@) {
23         my %params=@_;
24         my $format=shift;
25         shift;
26         my $text=IkiWiki::preprocess($params{page}, $params{destpage}, shift);
27         shift;
28
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;
47
48                 error(sprintf(gettext("unsupported page format %s"), $format));
49         }
50 }
51
52 1