]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
Merge branch 'master' into autoconfig
authorJoey Hess <joey@kodama.kitenet.net>
Sun, 27 Jul 2008 03:22:42 +0000 (23:22 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Sun, 27 Jul 2008 03:22:42 +0000 (23:22 -0400)
IkiWiki/Plugin/cutpaste.pm [new file with mode: 0644]
IkiWiki/Plugin/toggle.pm
debian/changelog
debian/copyright
doc/plugins/cutpaste.mdwn [new file with mode: 0644]

diff --git a/IkiWiki/Plugin/cutpaste.pm b/IkiWiki/Plugin/cutpaste.pm
new file mode 100644 (file)
index 0000000..b1161ba
--- /dev/null
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::cutpaste;
+
+use warnings;
+use strict;
+use IkiWiki 2.00;
+use UNIVERSAL;
+
+my %savedtext;
+
+sub import { #{{{
+       hook(type => "preprocess", id => "cut", call => \&preprocess_cut, scan => 1);
+       hook(type => "preprocess", id => "copy", call => \&preprocess_copy, scan => 1);
+       hook(type => "preprocess", id => "paste", call => \&preprocess_paste);
+} # }}}
+
+sub preprocess_cut (@) { #{{{
+       my %params=@_;
+
+       foreach my $param (qw{id text}) {
+               if (! exists $params{$param}) {
+                       error sprintf(gettext('%s parameter is required'), $param);
+               }
+       }
+
+       $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
+       $savedtext{$params{page}}->{$params{id}} = $params{text};
+
+       return "" if defined wantarray;
+} # }}}
+
+sub preprocess_copy (@) { #{{{
+       my %params=@_;
+
+       foreach my $param (qw{id text}) {
+               if (! exists $params{$param}) {
+                       error sprintf(gettext('%s parameter is required'), $param);
+               }
+       }
+
+       $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
+       $savedtext{$params{page}}->{$params{id}} = $params{text};
+
+       return IkiWiki::preprocess($params{page}, $params{destpage}, 
+               IkiWiki::filter($params{page}, $params{destpage}, $params{text})) if defined wantarray;
+} # }}}
+
+sub preprocess_paste (@) { #{{{
+       my %params=@_;
+
+       foreach my $param (qw{id}) {
+               if (! exists $params{$param}) {
+                       error sprintf(gettext('%s parameter is required'), $param);
+               }
+       }
+
+       if (! exists $savedtext{$params{page}}) {
+               error gettext('no text was copied in this page');
+       }
+       if (! exists $savedtext{$params{page}}->{$params{id}}) {
+               error sprintf(gettext('no text was copied in this page with id %s'), $params{id});
+       }
+
+       return IkiWiki::preprocess($params{page}, $params{destpage}, 
+               IkiWiki::filter($params{page}, $params{destpage}, $savedtext{$params{page}}->{$params{id}}));
+} # }}}
+
+1;
index cd9617e259d5433f561faabb4719abc7756c8d75..e203defb09f602f462ceac269d6742651691802c 100644 (file)
@@ -110,7 +110,7 @@ sub preprocess_toggleable (@) { #{{{
 sub format (@) { #{{{
         my %params=@_;
 
-       if ($params{content}=~s!(<div class="toggleable(?:-open)?" id="[^"]+">)</div>!$1!g) {
+       if ($params{content}=~s!(<div class="toggleable(?:-open)?" id="[^"]+">\s*)</div>!$1!g) {
                $params{content}=~s/<div class="toggleableend">//g;
                if (! ($params{content}=~s!^<body>!<body>$javascript!m)) {
                        # no </body> tag, probably in preview mode
index 78a18b615ae8cfa988a6c82f05562ca49f000122..08be87fbecdff3759e4ababcff1deae83136cf38 100644 (file)
@@ -41,6 +41,8 @@ ikiwiki (2.55) UNRELEASED; urgency=low
   * toggle: Fix incompatability between javascript and webkit.
   * bzr: Add support for rename and delete. (Jelmer Vernooij)
   * attachment: Use relative paths when inserting links.
+  * toggle: Fix for when html got tidied. Closes: #492529 (Enrico Zini)
+  * cutpaste: New plugin by Enrico Zini
 
  -- Joey Hess <joeyh@debian.org>  Mon, 21 Jul 2008 11:35:46 -0400
 
index d25e0861ac759779bd78126408ca79d1770a953d..d22edb03bc99b6a74542488370d1fe3361195bd4 100644 (file)
@@ -76,7 +76,7 @@ Files: htmltidy.pm
 Copyright: © 2006 Faidon Liambotis
 License: GPL-2+
 
-Files: polygen.pm, pagestats.pm
+Files: polygen.pm, pagestats.pm, cutpaste.pm
 Copyright: © 2006 Enrico Zini
 License: GPL-2+
 
diff --git a/doc/plugins/cutpaste.mdwn b/doc/plugins/cutpaste.mdwn
new file mode 100644 (file)
index 0000000..a5dff08
--- /dev/null
@@ -0,0 +1,55 @@
+[[!template id=plugin name=toggle author="[[Enrico]]"]]
+[[!tag type/chrome]]
+
+With this plugin you can store and recall pieces of text.  It defines three
+preprocessing commands:
+
+ * `\[[!cut id=name text="text"]]` memorizes the text allowing to recall it
+   using the given ID.  The text being cut is not included in the output.
+ * `\[[!copy id=name text="text"]]` memorizes the text allowing to recall it
+   using the given ID.  The text being cut *is* included in the output.
+ * `\[[!paste id=name]]` is replaced by the previously memorized text.
+
+The text being cut, copied and pasted can freely include wiki markup, including
+more calls to cut, copy and paste.
+
+You do not need to memorize the text before using it: a cut directive can
+follow the paste directive that uses its text.  In fact, this is quite useful
+to postpone big blocks of text like long annotations and have a more natural
+flow.  For example:
+
+       This plugin provides three directives:
+
+        * \[[!toggle id="cut" text="cut"]] that cuts text
+        * \[[!toggle id="copy" text="copy"]] that copies text
+        * \[[!toggle id="paste" text="paste"]] that pastes text
+
+       \[[!toggleable id="cut" text="\[[!paste id=cutlongdesc]]"]]
+       \[[!toggleable id="copy" text="\[[!paste id=copylongdesc]]"]]
+       \[[!toggleable id="paste" text="\[[!paste id=pastelongdesc]]"]]
+
+       \[...some time later...]
+
+       \[[!cut id=cutlongdesc text="""
+          blah blah blah
+       """]]
+       \[[!cut id=copylongdesc text="""
+          blah blah blah
+       """]]
+       \[[!cut id=pastelongdesc text="""
+          blah blah blah
+       """]]
+
+This can potentially be used to create loops, but ikiwiki is clever and breaks
+them.
+
+Since you can paste without using double quotes, copy and paste can be used to
+nest directive that require multiline parameters inside each other:
+
+       \[[!toggleable id=foo text="""
+         \[[!toggleable id=bar text="\[[!paste id=baz]]"]]
+       """]]
+
+       \[[!cut id=baz text="""
+       multiline parameter!
+       """]]