;
close( FILE );
my @subs;
my $body = '';
for( my $i = 0; $i < scalar( @lines ); $i++ ) {
my $line = $lines[$i];
# Remove leading spaces
$line =~ s/^[\t\s]+//;
# Remove multiple inner space
$line =~ s/[\t\s]+/ /;
if( $line =~ /^sub ([\d\w_-]+)[\s{]+$/ ) {
my $h2 = "";
$body .= '
' . $h2 . $1 . "()
\n";
# We've found one!
my $comments = '';
# Now we go backwards, nabbing the comments as we go
for( my $n = $i - 1; $n > 0; $n-- ) {
if( $lines[$n] =~ /#[\w\d\s\t]*/ ) {
# Becase we're now reading backwards,
# we need to prepend
$comments = lineToHtml( $lines[$n] ) . $comments;
} else {
# Exit and continue
$n = 0;
}
}
my $pStyle = "";
$comments = $pStyle . $comments . "
\n";
$body .= $comments;
}
}
$body .= "\n\n";
print bodyToHtml( $body );
exit( 0 );
}
sub bodyToHtml {
my $body = $_[0];
my $bodyHeader = '';
$bodyHeader .= '';
$bodyHeader .= '';
my $bodyFooter = '';
return $bodyHeader . $body . $bodyFooter;
}
sub lineToHtml {
my $line = $_[0];
my $formatted = $line;
$formatted =~ s/^[#\s\t]+//;
$formatted =~ s/\n+//;
if( $formatted =~ /^\@param/ ) {
$formatted =~ s/\@param/\@param<\/strong>/;
$formatted = '
' . $formatted . '';
} elsif( $formatted =~ /^\@return/ ) {
$formatted =~ s/\@return/\@return<\/strong>/;
$formatted = '
' . $formatted . '';
}
$formatted =~ s/ (int|hash|array|string|boolean|bool) / $1<\/span> /i;
$formatted .= "\n";
return $formatted;
}
----
// vim: set syntax=asciidoc: