summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/wmd.pm
blob: 3372ffe38dc35c115829eceba24e06d165045e4b (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::wmd;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.00;
  6. use POSIX;
  7. use Encode;
  8. sub import {
  9. add_underlay("wmd");
  10. hook(type => "getsetup", id => "wmd", call => \&getsetup);
  11. hook(type => "formbuilder_setup", id => "wmd", call => \&formbuilder_setup);
  12. }
  13. sub getsetup () {
  14. return
  15. plugin => {
  16. safe => 1,
  17. },
  18. }
  19. sub formbuilder_setup (@) {
  20. my %params=@_;
  21. my $form=$params{form};
  22. return if ! defined $form->field("do");
  23. return unless (($form->field("do") eq "edit") ||
  24. ($form->field("do") eq "create"));
  25. $form->tmpl_param("wmd_preview", "<div class=\"wmd-preview\"></div>\n".
  26. include_javascript(undef, 1));
  27. }
  28. sub include_javascript ($;$) {
  29. my $page=shift;
  30. my $absolute=shift;
  31. return '<script src="'.urlto("wmd.js", $page, $absolute).
  32. '" type="text/javascript"></script>'."\n";
  33. }
  34. 1