This commit is contained in:
Peter J. Holzer 2016-03-01 15:27:59 +01:00
parent 1ba676b1ff
commit fc037ed9e0
1 changed files with 34 additions and 1 deletions

View File

@ -34,10 +34,21 @@ my $locks = $sth->fetchall_arrayref();
binmode STDOUT, ":encoding(UTF-8)";
say "<!DOCTYPE html";
say "<!DOCTYPE html>";
say "<html>";
say "<head>";
say "<meta charset='UTF-8'/>";
say "<style type='text/css'>";
say "table { border-collapse: collapse; border-style: solid; border-width: 1px; }";
say "th { vertical-align: baseline; border-style: solid; border-color: #888; border-width: 1px; }";
say "td {";
say " vertical-align: baseline;";
say " border-style: solid;";
say " border-color: #888;";
say " border-width: 1px;";
say " white-space: pre-wrap }";
say "}";
say "</style>";
say "</head>";
say "<body>";
@ -71,3 +82,25 @@ sub xmlencode {
return encode("us-ascii", $s, FB_XMLCREF);
}
sub format_pretty {
my ($s) = @_;
if (!defined $s) { return '<em>NULL</em>' }
$s = xmlencode($s);
my @s = split(/\n/, $s);
while (@s && $s[0] eq "") { shift @s }
while (@s && $s[-1] eq "") { pop @s }
my $leading_space = "+Inf";
for (@s) {
my $sp = /^(\s+)/;
if (length($sp) < $leading_space) {
$leading_space = length($sp);
}
}
for (@s) {
$_ = substr($_, $leading_space);
}
$s = join("\n", @s);
return $s;
}