2 package IkiWiki::Plugin::cutpaste;
12 hook(type => "preprocess", id => "cut", call => \&preprocess_cut, scan => 1);
13 hook(type => "preprocess", id => "copy", call => \&preprocess_copy, scan => 1);
14 hook(type => "preprocess", id => "paste", call => \&preprocess_paste);
17 sub preprocess_cut (@) { #{{{
20 foreach my $param (qw{id text}) {
21 if (! exists $params{$param}) {
22 error sprintf(gettext('%s parameter is required'), $param);
26 $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
27 $savedtext{$params{page}}->{$params{id}} = $params{text};
29 return "" if defined wantarray;
32 sub preprocess_copy (@) { #{{{
35 foreach my $param (qw{id text}) {
36 if (! exists $params{$param}) {
37 error sprintf(gettext('%s parameter is required'), $param);
41 $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
42 $savedtext{$params{page}}->{$params{id}} = $params{text};
44 return IkiWiki::preprocess($params{page}, $params{destpage},
45 IkiWiki::filter($params{page}, $params{destpage}, $params{text})) if defined wantarray;
48 sub preprocess_paste (@) { #{{{
51 foreach my $param (qw{id}) {
52 if (! exists $params{$param}) {
53 error sprintf(gettext('%s parameter is required'), $param);
57 if (! exists $savedtext{$params{page}}) {
58 error gettext('no text was copied in this page');
60 if (! exists $savedtext{$params{page}}->{$params{id}}) {
61 error sprintf(gettext('no text was copied in this page with id %s'), $params{id});
64 return IkiWiki::preprocess($params{page}, $params{destpage},
65 IkiWiki::filter($params{page}, $params{destpage}, $savedtext{$params{page}}->{$params{id}}));