]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/comments.pm
comments: don't rely on mdwn getting loaded first
[git.ikiwiki.info.git] / IkiWiki / Plugin / comments.pm
index b5773554560cb155d2c576d7f5aaac5787a8cd48..29dc06f32c8907f37a178ef6710c7ca5f54a05fe 100644 (file)
@@ -17,8 +17,7 @@ sub import { #{{{
        hook(type => "getsetup", id => 'comments',  call => \&getsetup);
        hook(type => "preprocess", id => 'comments', call => \&preprocess);
        hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi);
-       hook(type => "htmlize", id => "_comment",
-               call => \&IkiWiki::Plugin::mdwn::htmlize);
+       hook(type => "htmlize", id => "_comment", call => \&htmlize);
        IkiWiki::loadplugin("inline");
        IkiWiki::loadplugin("mdwn");
 } # }}}
@@ -232,7 +231,7 @@ sub sessioncgi ($$) { #{{{
        my $body = $form->field('body') || '';
        $body =~ s/\r\n/\n/g;
        $body =~ s/\r/\n/g;
-       $body = "\n" if $body !~ /\n$/;
+       $body .= "\n" if $body !~ /\n$/;
 
        unless ($allow_directives) {
                # don't allow new-style directives at all
@@ -250,6 +249,17 @@ sub sessioncgi ($$) { #{{{
                $body =~ s/>/>/g;
        }
 
+       IkiWiki::run_hooks(sanitize => sub {
+               # $fake is a possible location for this comment. We don't
+               # know yet what the comment number *actually* is.
+               my $fake = "$page/_comment_1";
+               $body=shift->(
+                       page => $fake,
+                       destpage => $fake,
+                       content => $body,
+               );
+       });
+
        # In this template, the [[!meta]] directives should stay at the end,
        # so that they will override anything the user specifies. (For
        # instance, [[!meta author="I can fake the author"]]...)
@@ -268,9 +278,9 @@ sub sessioncgi ($$) { #{{{
        # - this means that if they do, rocks fall and everyone dies
 
        if ($form->submitted eq PREVIEW) {
-               # $fake is a location that has the same number of slashes
-               # as the eventual location of this comment.
-               my $fake = "$page/_comments_hypothetical";
+               # $fake is a possible location for this comment. We don't
+               # know yet what the comment number *actually* is.
+               my $fake = "$page/_comment_1";
                my $preview = IkiWiki::htmlize($fake, $page, 'mdwn',
                                IkiWiki::linkify($page, $page,
                                        IkiWiki::preprocess($page, $page,