summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/format.pm
blob: c8041209fc97b7324a9938a656da012b753c6456 (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. hook(type => "getsetup", id => "format", call => \&getsetup);
  9. }
  10. sub getsetup () {
  11. return
  12. plugin => {
  13. safe => 1,
  14. rebuild => undef,
  15. },
  16. }
  17. sub preprocess (@) {
  18. my %params=@_;
  19. my $format=shift;
  20. shift;
  21. my $text=IkiWiki::preprocess($params{page}, $params{destpage}, shift);
  22. shift;
  23. if (! defined $format || ! defined $text) {
  24. error(gettext("must specify format and text"));
  25. }
  26. elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
  27. return IkiWiki::htmlize($params{page}, $params{destpage},
  28. $format, $text);
  29. }
  30. else {
  31. # Other plugins can register htmlizefallback
  32. # hooks to add support for page types
  33. # not suitable for htmlize. Try them until
  34. # one succeeds.
  35. my $ret;
  36. IkiWiki::run_hooks(htmlizefallback => sub {
  37. $ret=shift->($format, $text)
  38. unless defined $ret;
  39. });
  40. return $ret if defined $ret;
  41. error(sprintf(gettext("unsupported page format %s"), $format));
  42. }
  43. }
  44. 1