-} # }}}
-
-sub htmlize { # {{{
- my %params = @_;
- return $params{content};
-} # }}}
-
-sub preprocess { # {{{
- my %params = @_;
- my $page = $params{page};
-
- my $format = $params{format};
- if (defined $format && !exists $IkiWiki::hooks{htmlize}{$format}) {
- error(sprintf(gettext("unsupported page format %s"), $format));
- }
-
- my $content = $params{content};
- if (!defined $content) {
- error(gettext("comment must have content"));
- }
- $content =~ s/\\"/"/g;
-
- $content = IkiWiki::filter($page, $params{destpage}, $content);
-
- if ($config{comments_allowdirectives}) {
- $content = IkiWiki::preprocess($page, $params{destpage},
- $content);
- }
-
- # no need to bother with htmlize if it's just HTML
- $content = IkiWiki::htmlize($page, $params{destpage}, $format,
- $content) if defined $format;
-
- IkiWiki::run_hooks(sanitize => sub {
- $content = shift->(
- page => $page,
- destpage => $params{destpage},
- content => $content,
- );
- });
-
- # override any metadata
-
- if (defined $params{username}) {
- my ($authorurl, $author) = linkuser($params{username});
- $pagestate{$page}{meta}{author} = $author;
- $pagestate{$page}{meta}{authorurl} = $authorurl;
- }
- elsif (defined $params{ip}) {
- $pagestate{$page}{meta}{author} = sprintf(
- gettext("Anonymous (IP: %s)"),
- $params{ip});
- delete $pagestate{$page}{meta}{authorurl};
- }
- else {
- $pagestate{$page}{meta}{author} = gettext("Anonymous");
- delete $pagestate{$page}{meta}{authorurl};
- }
-
- if (defined $params{subject}) {
- $pagestate{$page}{meta}{title} = $params{subject};
- }
- else {
- delete $pagestate{$page}{meta}{title};
- }
-
- my $baseurl = urlto($params{destpage}, undef, 1);
- my $anchor = "";
- my $comments_pagename = $config{comments_pagename};
- if ($params{page} =~ m/\/(\Q${comments_pagename}\E\d+)$/) {
- $anchor = $1;
- }
- $pagestate{$page}{meta}{permalink} = "${baseurl}#${anchor}";
-
- eval q{use Date::Parse};
- if (! $@) {
- my $time = str2time($params{date});
- $IkiWiki::pagectime{$page} = $time if defined $time;
- }
-
- # FIXME: hard-coded HTML (although it's just to set an ID)
- return "<div id=\"$anchor\">$content</div>" if $anchor;
- return $content;
-} # }}}