Prettify
This commit is contained in:
parent
1ba676b1ff
commit
fc037ed9e0
|
@ -34,10 +34,21 @@ my $locks = $sth->fetchall_arrayref();
|
||||||
|
|
||||||
|
|
||||||
binmode STDOUT, ":encoding(UTF-8)";
|
binmode STDOUT, ":encoding(UTF-8)";
|
||||||
say "<!DOCTYPE html";
|
say "<!DOCTYPE html>";
|
||||||
say "<html>";
|
say "<html>";
|
||||||
say "<head>";
|
say "<head>";
|
||||||
say "<meta charset='UTF-8'/>";
|
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 "</head>";
|
||||||
say "<body>";
|
say "<body>";
|
||||||
|
|
||||||
|
@ -71,3 +82,25 @@ sub xmlencode {
|
||||||
return encode("us-ascii", $s, FB_XMLCREF);
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue