From ea53b85d087c39fb5a8b17bc4156b83ac49ace77 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 22 Jun 2016 07:30:52 +0000 Subject: *** empty log message *** --- doc/podtbl | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 doc/podtbl diff --git a/doc/podtbl b/doc/podtbl new file mode 100755 index 0000000..8d910e4 --- /dev/null +++ b/doc/podtbl @@ -0,0 +1,99 @@ +#!/usr/bin/perl + +use Pod::Parser; +use List::Util qw(max); + +@ISA = Pod::Parser::; + +sub stripfcodes { + # strip formatting codes, dumb version + map { + s/[IBCLFSXZ]<< (.*?) >>/$1/gs; + s/[IBCLFSXZ]<(.*?)>/$1/gs; + $_ + } @$_; +} + +sub htmlfcodes { + my %tag = ( + I => "i", + B => "b", + C => "tt", + L => "i", # broken + F => "tt", + S => "nobr", # non-std + X => "span", # broken + Z => "span", # broken + ); + # strip formatting codes, dumb version + map { + s/([IBCLFSXZ])<< (.*?) >>/<$tag{$1}>$2<\/$tag{$1}>/gs; + s/([IBCLFSXZ])<(.*?)>/<$tag{$1}>$2<\/$tag{$1}>/gs; + $_ + } @$_; +} + +sub command { + my ($self, $command, $paragraph) = @_; + + if ($command eq "begin" && $paragraph =~ /^\s*table\s*$/s) { + $table++; + } elsif ($command eq "end" && $paragraph =~ /^\s*table\s*$/s) { + $table--; + } else { + shift; + return $self->SUPER::command (@_); + } +} + +sub verbatim { + my ($self, $para) = @_; + shift; + + return $self->SUPER::verbatim (@_) unless $table; + + my $table = [ map [$_ =~ /\t([^\t]*)/g], split /\n/, $para ]; + my $cols = max map scalar @$_, @$table; + + my $fh = $self->output_handle; + + # format the table + # text + print $fh "=begin text\n\n"; + + for (@$table) { + print $fh " ", (map +(sprintf "%-15s ", $_), stripfcodes @$_), "\n"; + } + + print $fh "\n=end text\n\n"; + + + # tbl + print $fh "=begin roff\n\n"; + + print $fh ".TS\n" . ("l " x $cols) . ".\n"; + print $fh map +(join "\t", stripfcodes @$_) . "\n", @$table; + print $fh ".TE\n"; + + print $fh "\n=end roff\n\n"; + + # html + # pod::xhtml fails on begin/end blocks +# print $fh "=begin xhtml\n\n"; + + print $fh "=for xhtml "; + print $fh map "", @$table; + print $fh "
" . +(join "", htmlfcodes @$_) . "
\n\n"; + + print $fh "=for html "; + print $fh map "", @$table; + print $fh "
" . +(join "", htmlfcodes @$_) . "
\n\n"; + +# print $fh "\n=end xhtml\n\n"; + +} + +__PACKAGE__->new->parse_from_filehandle; + + + -- cgit v1.2.3