From b66f9a1981094bc2159a228dfaefc5c2e01ee68a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 28 Jun 2008 23:08:24 -0400 Subject: [PATCH] call format hooks when generating page previews * toc: Revert change in 2.45 that made it run at sanitize time. This breaks use of toc in a sidebar. * Call format hooks when generating page previews, thus fixing toc display there, as well as fixing inlins to again display in page previews, since it's started using format hooks. This also allows several other things, like embed, that use format hooks, to work during page preview time. * Format hooks should not rely on getting an entire html document, as they will only get the body during page preview. * toggle: Deal with preview mode when adding javascript. --- IkiWiki/CGI.pm | 12 ++++-- IkiWiki/Plugin/toc.pm | 4 +- IkiWiki/Plugin/toggle.pm | 5 ++- debian/changelog | 9 ++++ doc/bugs/toc_in_sidebar.mdwn | 5 +++ doc/plugins/plaintext/.discussion.mdwn.swp | Bin 12288 -> 0 bytes doc/plugins/write.mdwn | 4 +- po/ikiwiki.pot | 46 ++++++++++----------- 8 files changed, 55 insertions(+), 30 deletions(-) delete mode 100644 doc/plugins/plaintext/.discussion.mdwn.swp diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 8a294e887..015c9ae01 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -396,11 +396,17 @@ sub cgi_editpage ($$) { #{{{ session => $session, ); }); - $form->tmpl_param("page_preview", - htmlize($page, $page, $type, + my $preview=htmlize($page, $page, $type, linkify($page, $page, preprocess($page, $page, - filter($page, $page, $content), 0, 1)))); + filter($page, $page, $content), 0, 1))); + run_hooks(format => sub { + $preview=shift->( + page => $page, + content => $preview, + ); + }); + $form->tmpl_param("page_preview", $preview); if ($new) { delete $pagesources{$page}; diff --git a/IkiWiki/Plugin/toc.pm b/IkiWiki/Plugin/toc.pm index 5380dd965..639cae4a9 100644 --- a/IkiWiki/Plugin/toc.pm +++ b/IkiWiki/Plugin/toc.pm @@ -9,7 +9,7 @@ use HTML::Parser; sub import { #{{{ hook(type => "preprocess", id => "toc", call => \&preprocess); - hook(type => "sanitize", id => "toc", call => \&sanitize); + hook(type => "format", id => "toc", call => \&format); } # }}} my %tocpages; @@ -33,7 +33,7 @@ sub preprocess (@) { #{{{ } } # }}} -sub sanitize (@) { #{{{ +sub format (@) { #{{{ my %params=@_; my $content=$params{content}; diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm index df5a2a737..8089443e0 100644 --- a/IkiWiki/Plugin/toggle.pm +++ b/IkiWiki/Plugin/toggle.pm @@ -112,7 +112,10 @@ sub format (@) { #{{{ if ($params{content}=~s!(
)
!$1!g) { $params{content}=~s/
//g; - $params{content}=~s!^<\/body>!$javascript!m; + if (! ($params{content}=~s!^<\/body>!$javascript!m)) { + # no tag, probably in preview mode + $params{content}.=$javascript; + } } return $params{content}; } # }}} diff --git a/debian/changelog b/debian/changelog index 0492ff87c..a89cb56e0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,6 +22,15 @@ ikiwiki (2.51) UNRELEASED; urgency=low * txt: New plugin, contributed by Gabriel McManus. * smiley: Generate links relative to the destpage. (Fixes a reversion from 2.41.) + * toc: Revert change in 2.45 that made it run at sanitize time. This breaks + use of toc in a sidebar. + * Call format hooks when generating page previews, thus fixing toc display + there, as well as fixing inlins to again display in page previews, since + it's started using format hooks. This also allows several other things, + like embed, that use format hooks, to work during page preview time. + * Format hooks should not rely on getting an entire html document, as they + will only get the body during page preview. + * toggle: Deal with preview mode when adding javascript. -- Joey Hess Sun, 15 Jun 2008 15:03:33 -0400 diff --git a/doc/bugs/toc_in_sidebar.mdwn b/doc/bugs/toc_in_sidebar.mdwn index 9286790b8..d2c3ab975 100644 --- a/doc/bugs/toc_in_sidebar.mdwn +++ b/doc/bugs/toc_in_sidebar.mdwn @@ -13,4 +13,9 @@ I can't think of a way between these that works in all cases. Maybe call the format hooks when generating a page preview? Maybe add an option to toc to make it embeddable in the sidebar? +Hmm, I think I need to call format during preview. Another case is that +inline uses a format hook to insert the inlined content.. + --[[Joey]] + +[[done]] diff --git a/doc/plugins/plaintext/.discussion.mdwn.swp b/doc/plugins/plaintext/.discussion.mdwn.swp deleted file mode 100644 index df2347f9eac4b56dc1422cafe0dde78db93ef831..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2&yL(g5XL)P5Rd>0LgYp*943)=JxM@{vf@BoA>ya9Y=Z^)dooTIk%X=d#1`tz$QA9j0r`Qyb0bgj6e zaJ{J1!I%2x&*xuNPk*A+XP&om`?PEAE8XhTRw?y`7@WsY&du5k(7f{Hyt936T%4EQ zrC^r$t&K~3FU>0x%RWZqUC~y9JKaHEkqKl1k0EeQy>a!*<=0=^qnFO#eayQ2C=lGw9Ffm3jbu1C`JP=+|>f{Q~_2{Rn*y zy$QVxJvgh>AJBKux6pm)E9e&V4D|PNO8o_W4}A^Yhi*X^pjRM?wBvFJ`7nahR7sJo=(oL7Idf4ZXNfq>*(k`oNPTlR_|yxZtE;-c#uu{ zk@xvS&oRMa>qc{_VOZ_RuSmX5r(v%v)oeQs*1$tS>JFZGXSY~lTulqoEjgbk_5og& zzE5Q0xF4rzHyq^5tXRY;S`JQI>Vw5|uT&Sf3%=wSk#}VRmkBsxp<2D>$wZOvC0hB= z>O?iW-Z+M5Ij?(Q&6@XVxg~9_A0!mHJw_>L)dFzW$frRxx`QKKHhZ){pr+!OxSKp^ z=loW7W5v>PyFb~9-d40^ zGA*ocxGGRgShiTzN2GZ7!^Pp@y9SMbVx~Sgxf2Ozjy<9m-s&U2lh?SU??}gok716T zIE(m9CK-I`qvWG$Wh{_WxpfP3(LFh5? z0*zhwn3>Unt~S~w$p;fQ)qQOEX>_MS1aEnL)QlM)Gs5a2U?dpP82FeDz{|^}r3Ux6 zC*&og$VeIq`wm@#{RqBpsCOk^IJNZ6ZZrXJ8Vvh_9D+w78d*HPS%zTHCSzzoI5bFY OK^-ctX&P~3S^W!fN)9Lh diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 35f391f7f..5def4c679 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -220,7 +220,9 @@ and should return the sanitized content. The difference between format and sanitize is that sanitize only acts on the page body, while format can modify the entire html page including the -header and footer inserted by ikiwiki, the html document type, etc. +header and footer inserted by ikiwiki, the html document type, etc. (It +should not rely on always being passed the entire page, as it won't be +when the page is being previewed.) The function is passed named parameters: "page" and "content", and should return the formatted content. diff --git a/po/ikiwiki.pot b/po/ikiwiki.pot index 6989e9579..fec552220 100644 --- a/po/ikiwiki.pot +++ b/po/ikiwiki.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2008-06-13 15:17-0400\n" +"POT-Creation-Date: 2008-06-28 23:05-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -24,7 +24,7 @@ msgstr "" msgid "login failed, perhaps you need to turn on cookies?" msgstr "" -#: ../IkiWiki/CGI.pm:190 ../IkiWiki/CGI.pm:521 +#: ../IkiWiki/CGI.pm:190 ../IkiWiki/CGI.pm:527 msgid "Your login session has expired." msgstr "" @@ -49,25 +49,25 @@ msgstr "" msgid "%s is not an editable page" msgstr "" -#: ../IkiWiki/CGI.pm:432 ../IkiWiki/Plugin/brokenlinks.pm:24 +#: ../IkiWiki/CGI.pm:438 ../IkiWiki/Plugin/brokenlinks.pm:24 #: ../IkiWiki/Plugin/inline.pm:266 ../IkiWiki/Plugin/opendiscussion.pm:17 #: ../IkiWiki/Plugin/orphans.pm:28 ../IkiWiki/Render.pm:95 #: ../IkiWiki/Render.pm:162 msgid "discussion" msgstr "" -#: ../IkiWiki/CGI.pm:488 +#: ../IkiWiki/CGI.pm:494 #, perl-format msgid "creating %s" msgstr "" -#: ../IkiWiki/CGI.pm:506 ../IkiWiki/CGI.pm:534 ../IkiWiki/CGI.pm:544 -#: ../IkiWiki/CGI.pm:578 ../IkiWiki/CGI.pm:623 +#: ../IkiWiki/CGI.pm:512 ../IkiWiki/CGI.pm:540 ../IkiWiki/CGI.pm:550 +#: ../IkiWiki/CGI.pm:584 ../IkiWiki/CGI.pm:629 #, perl-format msgid "editing %s" msgstr "" -#: ../IkiWiki/CGI.pm:716 +#: ../IkiWiki/CGI.pm:722 msgid "You are banned." msgstr "" @@ -84,62 +84,62 @@ msgstr "" msgid "missing %s parameter" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:161 +#: ../IkiWiki/Plugin/aggregate.pm:168 msgid "new feed" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:175 +#: ../IkiWiki/Plugin/aggregate.pm:182 msgid "posts" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:177 +#: ../IkiWiki/Plugin/aggregate.pm:184 msgid "new" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:340 +#: ../IkiWiki/Plugin/aggregate.pm:347 #, perl-format msgid "expiring %s (%s days old)" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:347 +#: ../IkiWiki/Plugin/aggregate.pm:354 #, perl-format msgid "expiring %s" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:374 +#: ../IkiWiki/Plugin/aggregate.pm:381 #, perl-format msgid "processed ok at %s" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:378 +#: ../IkiWiki/Plugin/aggregate.pm:385 #, perl-format msgid "checking feed %s ..." msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:383 +#: ../IkiWiki/Plugin/aggregate.pm:390 #, perl-format msgid "could not find feed at %s" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:398 +#: ../IkiWiki/Plugin/aggregate.pm:405 msgid "feed not found" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:409 +#: ../IkiWiki/Plugin/aggregate.pm:416 #, perl-format msgid "(invalid UTF-8 stripped from feed)" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:415 +#: ../IkiWiki/Plugin/aggregate.pm:422 #, perl-format msgid "(feed entities escaped)" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:421 +#: ../IkiWiki/Plugin/aggregate.pm:428 msgid "feed crashed XML::Feed!" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:495 +#: ../IkiWiki/Plugin/aggregate.pm:502 #, perl-format msgid "creating new page %s" msgstr "" @@ -285,15 +285,15 @@ msgstr "" msgid "failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)" msgstr "" -#: ../IkiWiki/Plugin/meta.pm:132 +#: ../IkiWiki/Plugin/meta.pm:137 msgid "stylesheet not found" msgstr "" -#: ../IkiWiki/Plugin/meta.pm:166 +#: ../IkiWiki/Plugin/meta.pm:171 msgid "redir page not found" msgstr "" -#: ../IkiWiki/Plugin/meta.pm:179 +#: ../IkiWiki/Plugin/meta.pm:184 msgid "redir cycle is not allowed" msgstr "" -- 2.39.5