localstyle: New plugin, allows overrding the toplevel local.css with one that is...
[ikiwiki] / 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 }
11
12 sub preprocess (@) {
13         my %params=@_;
14         my $format=shift;
15         shift;
16         my $text=IkiWiki::preprocess($params{page}, $params{destpage}, shift);
17         shift;
18
19         if (! defined $format || ! defined $text) {
20                 error(gettext("must specify format and text"));
21         }
22         elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
23                 return IkiWiki::htmlize($params{page}, $params{destpage},
24                                         $format, $text);
25         }
26         else {
27                 # Other plugins can register htmlizefallback
28                 # hooks to add support for page types
29                 # not suitable for htmlize. Try them until
30                 # one succeeds.
31                 my $ret;
32                 IkiWiki::run_hooks(htmlizefallback => sub {
33                         $ret=shift->($format, $text)
34                                 unless defined $ret;
35                 });
36                 return $ret if defined $ret;
37
38                 error(sprintf(gettext("unsupported page format %s"), $format));
39         }
40 }
41
42 1