]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/wmd.pm
rebuild not needed
[ikiwiki.git] / IkiWiki / Plugin / wmd.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::wmd;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
7 use POSIX;
8 use Encode;
9
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 }
15
16 sub getsetup () {
17         return
18                 plugin => {
19                         safe => 1,
20                 },
21 }
22
23 sub formbuilder_setup (@) {
24         my %params=@_;
25         my $form=$params{form};
26
27         return if ! defined $form->field("do");
28         
29         return unless (($form->field("do") eq "edit") ||
30                                 ($form->field("do") eq "create"));
31
32         $form->tmpl_param("wmd_preview", "<div class=\"wmd-preview\"></div>\n".
33                 include_javascript(undef, 1));
34 }
35
36 sub include_javascript ($;$) {
37         my $page=shift;
38         my $absolute=shift;
39         
40         return '<script src="'.urlto("wmd.js", $page, $absolute).
41                 '" type="text/javascript"></script>'."\n";
42 }
43
44 1