-This is the proposed patch to the second solution. I did not yet test it with the latest version of ikiwiki, but I did check that both plugins are identical in my test versions and the latest. I will update my wikis in use to the latest version and test it further, anyway.
-
-The part that could probably be removed in toc is the handler call "$p->handler(text => sub {" in line 110. It collects all text in the header as HTML::Parser "dtext", which means entities are decoded in the text. Since that step is probably already done in ikiwiki or doesn't need to be done (otherwise ikiwiki with toc.pm disabled would not work correctly) I'm pretty sure the "dtext" is not necessary. And in that case the patch below would just collect that text in the default handler. Not tested at all, I want to hear a second opinion first.
-
-**EDIT** Ok, the handler call is still necessary, but the "dtext" could be changed to "text". Also I needed to add 3 more lines, the patch below is up to date. It works with all markup and markdown I could think of. The only case not handled optimal is if the header is just a link and nothing else, then there is no text left for the local link, the toc links directly to a different page. Is that acceptable or not?
-
-(Should I upload this patch as a branch to ikiwiki.info? Not sure about how patch submission works here)
-
- diff --git a/IkiWiki/Plugin/toc.pm b/IkiWiki/Plugin/toc.pm
- index ac07b9a..5c2b056 100644
- --- a/IkiWiki/Plugin/toc.pm
- +++ b/IkiWiki/Plugin/toc.pm
- @@ -57,6 +57,7 @@ sub format (@) {
- my $startlevel=($params{startlevel} ? $params{startlevel} : 0);
- my $curlevel=$startlevel-1;
- my $liststarted=0;
- + my $headercollect=0;
- my $indent=sub { "\t" x $curlevel };
- $p->handler(start => sub {
- my $tagname=shift;
- @@ -107,6 +108,7 @@ sub format (@) {
- $index.=&$indent."<li class=\"L$curlevel\">".
- "<a href=\"#$anchor\">";
-
- + $headercollect=1;
- $p->handler(text => sub {
- $page.=join("", @_);
- $index.=join("", @_);
- @@ -117,12 +119,17 @@ sub format (@) {
- $p->handler(text => undef);
- $p->handler(end => undef);
- $index.="</a>\n";
- + $headercollect=0;
- + }
- + else {
- + $index.=join("",@_);
- }
- $page.=join("", @_);
- }, "tagname, text");
- }
- else {
- $page.=$text;
- + $index.=$text if ($headercollect);
- }
- }, "tagname, text");
- $p->handler(default => sub { $page.=join("", @_) }, "text");
- --
- 1.8.4.5
-
+This is the proposed patch to the second solution. Tested with the latest version. It works with all markup and markdown I could think of. The only case not handled optimal is if the header is just a link and nothing else, then there is no text left for the local link, the toc links directly to a different page. Is that acceptable or not?
+
+
+
+diff --git a/IkiWiki/Plugin/toc.pm b/IkiWiki/Plugin/toc.pm
+index ac07b9a..5c2b056 100644
+--- a/IkiWiki/Plugin/toc.pm
++++ b/IkiWiki/Plugin/toc.pm
+@@ -57,6 +57,7 @@ sub format (@) {
+ my $startlevel=($params{startlevel} ? $params{startlevel} : 0);
+ my $curlevel=$startlevel-1;
+ my $liststarted=0;
++ my $headercollect=0;
+ my $indent=sub { "\t" x $curlevel };
+ $p->handler(start => sub {
+ my $tagname=shift;
+@@ -107,6 +108,7 @@ sub format (@) {
+ $index.=&$indent."<li class=\"L$curlevel\">".
+ "<a href=\"#$anchor\">";
+
++ $headercollect=1;
+ $p->handler(text => sub {
+ $page.=join("", @_);
+ $index.=join("", @_);
+@@ -117,12 +119,17 @@ sub format (@) {
+ $p->handler(text => undef);
+ $p->handler(end => undef);
+ $index.="</a>\n";
++ $headercollect=0;
++ }
++ else {
++ $index.=join("",@_);
+ }
+ $page.=join("", @_);
+ }, "tagname, text");
+ }
+ else {
+ $page.=$text;
++ $index.=$text if ($headercollect);
+ }
+ }, "tagname, text");
+ $p->handler(default => sub { $page.=join("", @_) }, "text");
+
+
+[[!tag patch]]