summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/wmd.pm
blob: 9ddd237abf7e992f0e0d2dfdfa3daf3ed1c59baa (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->field("do") eq "comment";
  26. $form->tmpl_param("wmd_preview", "<div class=\"wmd-preview\"></div>\n".
  27. include_javascript(undef, 1));
  28. }
  29. sub include_javascript ($;$) {
  30. my $page=shift;
  31. my $absolute=shift;
  32. my $wmdjs=urlto("wmd/wmd.js", $page, $absolute);
  33. return <<"EOF"
  34. <script type="text/javascript">
  35. wmd_options = {
  36. output: "Markdown"
  37. };
  38. </script>
  39. <script src="$wmdjs" type="text/javascript"></script>
  40. EOF
  41. }
  42. 1