diff options
-rw-r--r-- | IkiWiki/Plugin/comments.pm | 24 | ||||
-rw-r--r-- | debian/changelog | 1 | ||||
-rw-r--r-- | templates/comment.tmpl | 2 |
3 files changed, 24 insertions, 3 deletions
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 5782d9083..2ad422f5f 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -224,7 +224,7 @@ sub preprocess { if ($params{page} =~ m/\/(\Q$config{comments_pagename}\E\d+)$/) { $pagestate{$page}{meta}{permalink} = urlto(IkiWiki::dirname($params{page}), undef, 1). - "#".$params{page}; + "#".page_to_id($params{page}); } eval q{use Date::Parse}; @@ -490,7 +490,8 @@ sub editcomment ($$) { # Jump to the new comment on the page. # The trailing question mark tries to avoid broken # caches and get the most recent version of the page. - IkiWiki::redirect($cgi, urlto($page, undef, 1)."?updated#$location"); + IkiWiki::redirect($cgi, urlto($page, undef, 1). + "?updated#".page_to_id($location)); } else { @@ -759,6 +760,10 @@ sub pagetemplate (@) { if (!exists $commentstate{$page}) { return; } + + if ($template->query(name => 'commentid')) { + $template->param(commentid => page_to_id($page)); + } if ($template->query(name => 'commentuser')) { $template->param(commentuser => @@ -808,6 +813,21 @@ sub unique_comment_location ($) { return $location; } +sub page_to_id ($) { + # Converts a comment page name into a unique, legal html id + # addtibute value, that can be used as an anchor to link to the + # comment. + my $page=shift; + + # It needs to start with a letter. + $page="comment_".$page; + + # Encode any illegal characters. + $page=~s/([^A-Za-z0-9-_:.])/"__".ord($1)."__"/eg; + + return $page; +} + package IkiWiki::PageSpec; sub match_postcomment ($$;@) { diff --git a/debian/changelog b/debian/changelog index 4ba32c8d6..158db9a4d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,7 @@ ikiwiki (3.09) UNRELEASED; urgency=low * css: Add clear: both to inlinefooter. * comments: Fix too loose test for comments pages that matched normal pages with "comment_" in their name. Closes: #521322 + * comments: Fix anchor ids to be legal xhtml. Closes: #521339 -- Joey Hess <joeyh@debian.org> Thu, 19 Mar 2009 15:32:49 -0400 diff --git a/templates/comment.tmpl b/templates/comment.tmpl index 1b9064ea0..fb76ea004 100644 --- a/templates/comment.tmpl +++ b/templates/comment.tmpl @@ -1,4 +1,4 @@ -<div class="comment" id="<TMPL_VAR NAME=INLINEPAGE>"> +<div class="comment" id="<TMPL_VAR NAME=COMMENTID>"> <div class="comment-subject"> <TMPL_IF PERMALINK> |