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