Use lockf rather than flock when taking the cgilock, for better portability.
[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         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                 
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         });
41
42         if (defined $ret) {
43                 return $ret;
44         }
45         elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
46                 return IkiWiki::htmlize($params{page}, $params{destpage},
47                                         $format, $text);
48         }
49         else {
50                 error(sprintf(gettext("unsupported page format %s"), $format));
51         }
52 }
53
54 1