]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/wmd.pm
Added a comment
[git.ikiwiki.info.git] / IkiWiki / Plugin / wmd.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::wmd;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
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 }
14 sub getsetup () {
15         return
16                 plugin => {
17                         safe => 1,
18                         rebuild => 0,
19                         section => "web",
20                 },
21 }
23 sub formbuilder_setup (@) {
24         my %params=@_;
25         my $form=$params{form};
27         return if ! defined $form->field("do");
28         
29         return unless $form->field("do") eq "edit" ||
30                         $form->field("do") eq "create" ||
31                         $form->field("do") eq "comment";
33         $form->tmpl_param("wmd_preview", "<div class=\"wmd-preview\"></div>\n".
34                 include_javascript(undef));
35 }
37 sub include_javascript ($) {
38         my $from=shift;
40         my $wmdjs=urlto("wmd/wmd.js", $from);
41         return <<"EOF"
42 <script type="text/javascript">
43 wmd_options = {
44         output: "Markdown"
45 };
46 </script>
47 <script src="$wmdjs" type="text/javascript"></script>
48 EOF
49 }
51 1