summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/format.pm
blob: 1513cbed72a67447fa8bcedd9bff1f10ce076262 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::format;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.00;
  6. sub import {
  7. hook(type => "preprocess", id => "format", call => \&preprocess);
  8. }
  9. sub preprocess (@) {
  10. my %params=@_;
  11. my $format=shift;
  12. shift;
  13. my $text=IkiWiki::preprocess($params{page}, $params{destpage}, shift);
  14. shift;
  15. if (! defined $format || ! defined $text) {
  16. error(gettext("must specify format and text"));
  17. }
  18. elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
  19. return IkiWiki::htmlize($params{page}, $params{destpage},
  20. $format, $text);
  21. }
  22. else {
  23. # Other plugins can register htmlizefallback
  24. # hooks to add support for page types
  25. # not suitable for htmlize. Try them until
  26. # one succeeds.
  27. my $ret;
  28. IkiWiki::run_hooks(htmlizefallback => sub {
  29. $ret=shift->($format, $text)
  30. unless defined $ret;
  31. });
  32. return $ret if defined $ret;
  33. error(sprintf(gettext("unsupported page format %s"), $format));
  34. }
  35. }
  36. 1