ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/doc/podtbl
Revision: 1.1
Committed: Thu Aug 12 21:30:14 2004 UTC (19 years, 10 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/usr/bin/perl
2
3 use Pod::Parser;
4 use List::Util qw(max);
5
6 @ISA = Pod::Parser::;
7
8 sub stripfcodes {
9 # strip formatting codes, dumb version
10 map {
11 s/[IBCLFSXZ]<< (.*?) >>/$1/gs;
12 s/[IBCLFSXZ]<(.*?)>/$1/gs;
13 $_
14 } @$_;
15 }
16
17 sub htmlfcodes {
18 my %tag = (
19 I => "i",
20 B => "b",
21 C => "tt",
22 L => "i", # broken
23 F => "tt",
24 S => "nobr", # non-std
25 X => "span", # brokwn
26 Z => "span", # brokwn
27 );
28 # strip formatting codes, dumb version
29 map {
30 s/([IBCLFSXZ])<< (.*?) >>/<$tag{$1}>$2<\/$tag{$1}>/gs;
31 s/([IBCLFSXZ])<(.*?)>/<$tag{$1}>$2<\/$tag{$1}>/gs;
32 $_
33 } @$_;
34 }
35
36 sub command {
37 my ($self, $command, $paragraph) = @_;
38
39 if ($command eq "begin" && $paragraph =~ /^\s*table\s*$/s) {
40 $table++;
41 } elsif ($command eq "end" && $paragraph =~ /^\s*table\s*$/s) {
42 $table--;
43 } else {
44 shift;
45 return $self->SUPER::command (@_);
46 }
47 }
48
49 sub verbatim {
50 my ($self, $para) = @_;
51 shift;
52
53 return $self->SUPER::verbatim (@_) unless $table;
54
55 my $table = [ map [$_ =~ /\t([^\t]*)/g], split /\n/, $para ];
56 my $cols = max map scalar @$_, @$table;
57
58 my $fh = $self->output_handle;
59
60 # format the table
61 # tbl first
62 print $fh "=begin roff\n\n";
63
64 print $fh ".TS\n" . ("l " x $cols) . ".\n";
65 print $fh map +(join "\t", stripfcodes @$_) . "\n", @$table;
66 print $fh ".TE\n\n";
67
68 print $fh "=end roff\n\n";
69
70 # html second
71 print $fh "=begin html\n\n";
72
73 print $fh "<table>\n";
74 print $fh map "<tr><td>" . +(join "</td><td>", htmlfcodes @$_) . "</td></tr>\n", @$table;
75 print $fh "</table>\n\n";
76
77 print $fh "=end html\n\n";
78
79 }
80
81 __PACKAGE__->new->parse_from_filehandle;
82
83
84