From 02078c406ca71780e45af0f4dea6ceafcd56c730 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Sat, 26 Jul 2008 23:05:22 +0100 Subject: [PATCH 1/5] Handle the case when HTML got tidied. This fixes debian bug #492529. --- IkiWiki/Plugin/toggle.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm index cd9617e25..e203defb0 100644 --- a/IkiWiki/Plugin/toggle.pm +++ b/IkiWiki/Plugin/toggle.pm @@ -110,7 +110,7 @@ sub preprocess_toggleable (@) { #{{{ sub format (@) { #{{{ my %params=@_; - if ($params{content}=~s!(
)
!$1!g) { + if ($params{content}=~s!(
\s*)
!$1!g) { $params{content}=~s/
//g; if (! ($params{content}=~s!^!$javascript!m)) { # no tag, probably in preview mode From 1c831b472b3d84342d649db01eb33718e3b5bd0c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 26 Jul 2008 23:06:40 -0400 Subject: [PATCH 2/5] changelog --- debian/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/changelog b/debian/changelog index 348d30997..5ed125d8f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -29,6 +29,7 @@ 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) -- Joey Hess Mon, 21 Jul 2008 11:35:46 -0400 From e3713772f76fa9cc3587e48d0326035a352270d9 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Sat, 26 Jul 2008 23:24:11 +0100 Subject: [PATCH 3/5] Added cutpaste plugin. I'm wondering if cutandpaste wouldn't be a better name. --- IkiWiki/Plugin/cutpaste.pm | 68 ++++++++++++++++++++++++++++++++++++++ doc/plugins/cutpaste.mdwn | 55 ++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 IkiWiki/Plugin/cutpaste.pm create mode 100644 doc/plugins/cutpaste.mdwn diff --git a/IkiWiki/Plugin/cutpaste.pm b/IkiWiki/Plugin/cutpaste.pm new file mode 100644 index 000000000..1737775d5 --- /dev/null +++ b/IkiWiki/Plugin/cutpaste.pm @@ -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}) { + return "[[cut ".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}) { + return "[[copy ".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}) { + return "[[paste ".sprintf(gettext('%s parameter is required'), $param)."]]"; + } + } + + if (! exists $savedtext{$params{page}}) { + return "[[paste ".gettext('no text was copied in this page')."]]"; + } + if (! exists $savedtext{$params{page}}->{$params{id}}) { + return "[[paste ".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; diff --git a/doc/plugins/cutpaste.mdwn b/doc/plugins/cutpaste.mdwn new file mode 100644 index 000000000..578502988 --- /dev/null +++ b/doc/plugins/cutpaste.mdwn @@ -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! + """]] From 618e3c107547d43a207ea2b7cad3a4e10e04cb04 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 26 Jul 2008 23:15:35 -0400 Subject: [PATCH 4/5] use new style error handling --- IkiWiki/Plugin/cutpaste.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/IkiWiki/Plugin/cutpaste.pm b/IkiWiki/Plugin/cutpaste.pm index 1737775d5..b1161ba06 100644 --- a/IkiWiki/Plugin/cutpaste.pm +++ b/IkiWiki/Plugin/cutpaste.pm @@ -19,7 +19,7 @@ sub preprocess_cut (@) { #{{{ foreach my $param (qw{id text}) { if (! exists $params{$param}) { - return "[[cut ".sprintf(gettext('%s parameter is required'), $param)."]]"; + error sprintf(gettext('%s parameter is required'), $param); } } @@ -34,7 +34,7 @@ sub preprocess_copy (@) { #{{{ foreach my $param (qw{id text}) { if (! exists $params{$param}) { - return "[[copy ".sprintf(gettext('%s parameter is required'), $param)."]]"; + error sprintf(gettext('%s parameter is required'), $param); } } @@ -50,15 +50,15 @@ sub preprocess_paste (@) { #{{{ foreach my $param (qw{id}) { if (! exists $params{$param}) { - return "[[paste ".sprintf(gettext('%s parameter is required'), $param)."]]"; + error sprintf(gettext('%s parameter is required'), $param); } } if (! exists $savedtext{$params{page}}) { - return "[[paste ".gettext('no text was copied in this page')."]]"; + error gettext('no text was copied in this page'); } if (! exists $savedtext{$params{page}}->{$params{id}}) { - return "[[paste ".sprintf(gettext('no text was copied in this page with id %s'), $params{id})."]]"; + error sprintf(gettext('no text was copied in this page with id %s'), $params{id}); } return IkiWiki::preprocess($params{page}, $params{destpage}, From ecc40d1769c84a2cca3070e848adfd8710f27d8b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 26 Jul 2008 23:15:50 -0400 Subject: [PATCH 5/5] changelog and tweaks --- debian/changelog | 1 + debian/copyright | 2 +- doc/plugins/cutpaste.mdwn | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 5ed125d8f..77a08c456 100644 --- a/debian/changelog +++ b/debian/changelog @@ -30,6 +30,7 @@ ikiwiki (2.55) UNRELEASED; urgency=low * 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 Mon, 21 Jul 2008 11:35:46 -0400 diff --git a/debian/copyright b/debian/copyright index d25e0861a..d22edb03b 100644 --- a/debian/copyright +++ b/debian/copyright @@ -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 index 578502988..a5dff08ab 100644 --- a/doc/plugins/cutpaste.mdwn +++ b/doc/plugins/cutpaste.mdwn @@ -50,6 +50,6 @@ nest directive that require multiline parameters inside each other: \[[!toggleable id=bar text="\[[!paste id=baz]]"]] """]] - [[!cut id=baz text=""" + \[[!cut id=baz text=""" multiline parameter! """]]