]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - doc/bugs/color_plugin_produces_artifacts_in_table-of-contents.mdwn
link to patch
[git.ikiwiki.info.git] / doc / bugs / color_plugin_produces_artifacts_in_table-of-contents.mdwn
index 0a8ee99c763102778b607f3bd90134f64a0b437b..d627091ea57df3c3c6c7d90a0fa8365b341ca1c8 100644 (file)
@@ -16,6 +16,11 @@ Reason for this behaviour is:
 1. the toc plugin removes everything except plain text from headers in the toc
 1. if the toc plugin is executed before the color plugin in the format hook it sees the special syntax and clobbers the toc, otherwise it just removes the color markup
 
+> The bug here is that the color plugin's special syntax does not
+> gracefully degrade to "render nothing", which I have now [[fixed|done]]
+> by putting the color bits through a value attribute instead of
+> character data. --[[smcv]]
+
 # Solutions
 
 There are a few possible solutions to this depending on how it should work:
@@ -26,6 +31,12 @@ There are a few possible solutions to this depending on how it should work:
 
 I would propose implementing the second option because visual markers in headers are useful to convey additional information very fast and this information should be preserved in the toc. Example: Bug or task/project tracker with color conveying status of the bug or task.
 
+> This is really a separate feature request: copy non-`<a>` markup
+> in headings into the TOC. I don't think this necessarily makes
+> sense in general. In particular, any `id` attributes on child
+> elements must not be passed through because that would make
+> the ID non-unique. --[[smcv]]
+
 It seems you can stuff anything into ordered lists (according to w3.orgs doku), so apart from stylistic reasons and suboptimal display of links in headers (see below) I don't see any problems with markup in the toc. 
 
 # Patch
@@ -34,44 +45,45 @@ This is the proposed patch to the second solution. Tested with the latest versio
 
 
 
-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");
+    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]]