summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/wmd.pm
blob: 71d7c9d17f51e49ec17aee087e984f3e8a7b9b79 (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, 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