summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/wmd.pm
blob: 134cfb9101b51d48bbabc6a47b7aaba1b73ff699 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::wmd;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.00;
  6. sub import {
  7. add_underlay("wmd");
  8. hook(type => "getsetup", id => "wmd", call => \&getsetup);
  9. hook(type => "formbuilder_setup", id => "wmd", call => \&formbuilder_setup);
  10. }
  11. sub getsetup () {
  12. return
  13. plugin => {
  14. safe => 1,
  15. rebuild => 0,
  16. section => "web",
  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));
  28. }
  29. sub include_javascript ($) {
  30. my $from=shift;
  31. my $wmdjs=urlto("wmd/wmd.js", $from);
  32. return <<"EOF"
  33. <script type="text/javascript">
  34. wmd_options = {
  35. output: "Markdown"
  36. };
  37. </script>
  38. <script src="$wmdjs" type="text/javascript"></script>
  39. EOF
  40. }
  41. 1