summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/format.pm
blob: b596bc0a10343b91cf7287f5b5fa06a81084b055 (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. # Other plugins can register htmlizeformat hooks to add support
  28. # for page types not suitable for htmlize, or that need special
  29. # processing when included via format. Try them until one succeeds.
  30. my $ret;
  31. IkiWiki::run_hooks(htmlizeformat => sub {
  32. $ret=shift->($format, $text)
  33. unless defined $ret;
  34. });
  35. if (defined $ret) {
  36. return $ret;
  37. }
  38. elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
  39. return IkiWiki::htmlize($params{page}, $params{destpage},
  40. $format, $text);
  41. }
  42. else {
  43. error(sprintf(gettext("unsupported page format %s"), $format));
  44. }
  45. }
  46. 1