aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/format.pm
blob: c8041209fc97b7324a9938a656da012b753c6456 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
package IkiWiki::Plugin::format;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type => "preprocess", id => "format", call => \&preprocess);
	hook(type => "getsetup",   id => "format", call => \&getsetup);
}

sub getsetup () {
	return
		plugin => {
			safe => 1,
			rebuild => undef,
		},
}

sub preprocess (@) {
	my %params=@_;
	my $format=shift;
	shift;
	my $text=IkiWiki::preprocess($params{page}, $params{destpage}, shift);
	shift;

	if (! defined $format || ! defined $text) {
		error(gettext("must specify format and text"));
	}
	elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
		return IkiWiki::htmlize($params{page}, $params{destpage},
		                        $format, $text);
	}
	else {
		# Other plugins can register htmlizefallback
		# hooks to add support for page types
		# not suitable for htmlize. Try them until
		# one succeeds.
		my $ret;
		IkiWiki::run_hooks(htmlizefallback => sub {
			$ret=shift->($format, $text)
				unless defined $ret;
		});
		return $ret if defined $ret;

		error(sprintf(gettext("unsupported page format %s"), $format));
	}
}

1