2 package IkiWiki::Plugin::cutpaste;
11 hook(type => "getsetup", id => "cutpaste", call => \&getsetup);
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);
25 sub preprocess_cut (@) {
28 foreach my $param (qw{id text}) {
29 if (! exists $params{$param}) {
30 error sprintf(gettext('%s parameter is required'), $param);
34 $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
35 $savedtext{$params{page}}->{$params{id}} = $params{text};
37 return "" if defined wantarray;
40 sub preprocess_copy (@) {
43 foreach my $param (qw{id text}) {
44 if (! exists $params{$param}) {
45 error sprintf(gettext('%s parameter is required'), $param);
49 $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
50 $savedtext{$params{page}}->{$params{id}} = $params{text};
52 return IkiWiki::preprocess($params{page}, $params{destpage},
53 IkiWiki::filter($params{page}, $params{destpage}, $params{text})) if defined wantarray;
56 sub preprocess_paste (@) {
59 foreach my $param (qw{id}) {
60 if (! exists $params{$param}) {
61 error sprintf(gettext('%s parameter is required'), $param);
65 if (! exists $savedtext{$params{page}}) {
66 error gettext('no text was copied in this page');
68 if (! exists $savedtext{$params{page}}->{$params{id}}) {
69 error sprintf(gettext('no text was copied in this page with id %s'), $params{id});
72 return IkiWiki::preprocess($params{page}, $params{destpage},
73 IkiWiki::filter($params{page}, $params{destpage}, $savedtext{$params{page}}->{$params{id}}));