%# BEGIN LICENSE BLOCK
%# 
%#  Copyright (c) 2002-2003 Jesse Vincent <jesse@bestpractical.com>
%#  
%#  This program is free software; you can redistribute it and/or modify
%#  it under the terms of version 2 of the GNU General Public License 
%#  as published by the Free Software Foundation.
%# 
%#  A copy of that license should have arrived with this
%#  software, but in any event can be snarfed from www.gnu.org.
%# 
%#  This program is distributed in the hope that it will be useful,
%#  but WITHOUT ANY WARRANTY; without even the implied warranty of
%#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%#  GNU General Public License for more details.
%# 
%# END LICENSE BLOCK
% if ($include{Name}) {
#<%$Article->Id%>: <%$Article->Name || loc('(no name)')%>
<%'-' x length("#".$Article->Id.": ".($Article->Name || loc('(no name)'))) %>
% }
% if ($Article->Summary =~ /\S/ and $include{Summary}) {
<% $Article->Summary%>
% }
% while (my $cf = $cfs->Next) {
%   next unless $include{"CF-Title-".$cf->Id} or $include{"CF-Value-".$cf->Id};
%   my $values = $Article->CustomFieldValues($cf->Id);

%   if ($values->Count == 1) {
%     my $value = $values->First; 
%     my $content = $value ? $value->Content : "";
%     if ($content =~ /<(.{1,5})>/) {
%       $content = de_htmlify($content);
%     }
%     if ($include{"CF-Title-".$cf->Id}) {
<%      $cf->Name%>:
<%      '-' x length($cf->Name) %>
%     }
%     if ($include{"CF-Value-".$cf->Id}) {
<%      $content%>
%     }
%   } else {
%     my $val = $values->Next;
%     my $content = $val ? $val->Content : "";
%     if ($content =~ /<(.{1,5})>/) {
%       $content = de_htmlify($content);
%     }
%     if ($include{"CF-Title-".$cf->Id}) {
<%      $cf->Name%>: \
%     }
%     if ($include{"CF-Value-".$cf->Id}) {
<%      $val && $content%>
%     }
%     while ($val = $values->Next) { 
%       my $content = $val->Content;
%       if ($content =~ /<(.{1,5})>/) {
%         $content = de_htmlify($content);
%       }
%       if ($include{"CF-Title-".$cf->Id}) {
<%        ' ' x length($cf->Name)%>  \
%       }
%       if ($include{"CF-Title-".$cf->Id}) {
<%        $content%>
%       }
%     } 
%   }
% }
<%init>
my $class = $Article->ClassObj;
my %include = (Name => 1, Summary => 1);
my $cfs = $class->ArticleCustomFields;
$include{"CF-Title-".$_->Id} = $include{"CF-Value-".$_->Id} = 1 while $_ = $cfs->Next;
$include{$_} = not $class->FirstAttribute("Skip-$_") for keys %include;

sub de_htmlify {
    my $content = shift;
    require HTML::TreeBuilder;
    my $tree = HTML::TreeBuilder->new;
    $tree->parse($content);
    $tree->eof();

    require HTML::FormatText;
    my $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin => 50);
    $content = $formatter->format($tree);
    return $content;
}
</%init>
<%args>
$Article
</%args>