]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/wmd.pm
074e1df6fc7c487ae888eda4f1e1fd8711d0c695
[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 => 1,
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"));
33         $form->tmpl_param("wmd_preview", "<div class=\"wmd-preview\"></div>\n".include_javascript(undef, 1));
34 }
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 }
44 1