]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/wmd.pm
moderatedcomments: Added moderate_pagespec
[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;
7 use POSIX;
8 use Encode;
10 sub import {
11         add_underlay("wmd");
12         hook(type => "getsetup", id => "wmd", call => \&getsetup);
13         hook(type => "formbuilder_setup", id => "wmd", call => \&formbuilder_setup);
14 }
16 sub getsetup () {
17         return
18                 plugin => {
19                         safe => 1,
20                         rebuild => 0,
21                         section => "web",
22                 },
23 }
25 sub formbuilder_setup (@) {
26         my %params=@_;
27         my $form=$params{form};
29         return if ! defined $form->field("do");
30         
31         return unless $form->field("do") eq "edit" ||
32                         $form->field("do") eq "create" ||
33                         $form->field("do") eq "comment";
35         $form->tmpl_param("wmd_preview", "<div class=\"wmd-preview\"></div>\n".
36                 include_javascript(undef, 1));
37 }
39 sub include_javascript ($;$) {
40         my $page=shift;
41         my $absolute=shift;
43         my $wmdjs=urlto("wmd/wmd.js", $page, $absolute);
44         return <<"EOF"
45 <script type="text/javascript">
46 wmd_options = {
47         output: "Markdown"
48 };
49 </script>
50 <script src="$wmdjs" type="text/javascript"></script>
51 EOF
52 }
54 1