summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/wmd.pm
blob: 5361d2914c078e1b25c275df75239a531298c97b (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. rebuild => 0,
  18. section => "web",
  19. },
  20. }
  21. sub formbuilder_setup (@) {
  22. my %params=@_;
  23. my $form=$params{form};
  24. return if ! defined $form->field("do");
  25. return unless $form->field("do") eq "edit" ||
  26. $form->field("do") eq "create" ||
  27. $form->field("do") eq "comment";
  28. $form->tmpl_param("wmd_preview", "<div class=\"wmd-preview\"></div>\n".
  29. include_javascript(undef, 1));
  30. }
  31. sub include_javascript ($;$) {
  32. my $page=shift;
  33. my $absolute=shift;
  34. my $wmdjs=urlto("wmd/wmd.js", $page, $absolute);
  35. return <<"EOF"
  36. <script type="text/javascript">
  37. wmd_options = {
  38. output: "Markdown"
  39. };
  40. </script>
  41. <script src="$wmdjs" type="text/javascript"></script>
  42. EOF
  43. }
  44. 1