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