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