ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/doc/podtbl
Revision: 1.2
Committed: Sat Aug 14 03:07:50 2004 UTC (19 years, 10 months ago) by root
Branch: MAIN
CVS Tags: rel-7_3, rel-7_2, rel-7_1, rel-7_0, rel-7_7, rel-7_6, rel-7_5, rel-7_8, rel-7_9, rel-5_5, rel-5_4, rel-5_7, rel-5_1, rel-5_0, rel-5_3, rel-5_2, rel-4_4, rel-4_6, rel-4_7, rel-5_9, rel-5_8, rel-4_2, rel-4_3, rel-3_7, rel-3_8, rel-7_4, rel-8_1, rel-6_2, rel-6_3, rel-7_3a, rel-6_0, rel-3_6, rel-8_0, rel-8_2, rel-4_1, rel-4_0, rel-6_1, rel-4_8, rel-4_9
Changes since 1.1: +16 -6 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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 root 1.2 # text
62     print $fh "=begin text\n\n";
63    
64     for (@$table) {
65     print $fh " ", (map +(sprintf "%-15s ", $_), stripfcodes @$_), "\n";
66     }
67    
68     print $fh "\n=end text\n\n";
69    
70    
71     # tbl
72 root 1.1 print $fh "=begin roff\n\n";
73    
74     print $fh ".TS\n" . ("l " x $cols) . ".\n";
75     print $fh map +(join "\t", stripfcodes @$_) . "\n", @$table;
76 root 1.2 print $fh ".TE\n";
77 root 1.1
78 root 1.2 print $fh "\n=end roff\n\n";
79 root 1.1
80 root 1.2 # html
81 root 1.1 print $fh "=begin html\n\n";
82    
83     print $fh "<table>\n";
84     print $fh map "<tr><td>" . +(join "</td><td>", htmlfcodes @$_) . "</td></tr>\n", @$table;
85 root 1.2 print $fh "</table>\n";
86 root 1.1
87 root 1.2 print $fh "\n=end html\n\n";
88 root 1.1
89     }
90    
91     __PACKAGE__->new->parse_from_filehandle;
92    
93    
94