WIP: uniproc
[hband-tools.git] / tabdata / td2html
blob1a1f1b67dbd3a609b455f3c3f930e97351e0280e
1 #!/usr/bin/env perl
3 =pod
5 =head1 NAME
7 td2html - Transform tabular data stream into a HTML table.
9 =head1 SYNOPSIS
11 td2html
13 =head1 DESCRIPTION
15 Takes a tabular data stream on STDIN and outputs a HTML table
16 enclosed in C<< <table>...</table> >> tags.
18 =cut
20 no if ($] >= 5.018), 'warnings' => 'experimental::smartmatch';
21 do '/usr/lib/tool/perl5/tabdata/common.pl' or die "$@";
23 sub html_escape
25 my $str = shift;
26 $str =~ s/[><&\t]/'&' . {'>'=>'gt', '<'=>'lt', '&'=>'amp', "\t"=>'Tab'}->{$&} . ';'/eg;
27 $str =~ s/\n/<br>/g;
28 return $str;
31 print "<table border=\"1\">\n";
33 print "<tr>";
34 print "<th>";
35 $header = <STDIN>;
36 chomp $header;
37 print join("</th><th>", map {html_escape(unescape_tabdata($_))} split $FS, $header);
38 print "</th>";
39 print "</tr>\n";
41 while($row = <STDIN>)
43 chomp $row;
44 print "<tr>";
45 print "<td>";
46 print join("</td><td>", map {html_escape(unescape_tabdata($_))} split $FS, $row);
47 print "</td>";
48 print "</tr>\n";
51 print "</table>";