| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::FormatText; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Format HTML as plaintext |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
22669
|
use 5.006_001; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
39
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
76
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
34
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# We now use Smart::Comments in place of the old DEBUG framework. |
|
11
|
|
|
|
|
|
|
# this should be commented out in release versions.... |
|
12
|
|
|
|
|
|
|
##use Smart::Comments; |
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
4
|
use base 'HTML::Formatter'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
777
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '2.11'; # VERSION |
|
17
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:NIGELM'; # AUTHORITY |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
20
|
|
|
|
|
|
|
sub default_values { |
|
21
|
10
|
|
|
10
|
0
|
50
|
( shift->SUPER::default_values(), |
|
22
|
|
|
|
|
|
|
lm => 3, # left margin |
|
23
|
|
|
|
|
|
|
rm => 72, # right margin (actually, maximum text width) |
|
24
|
|
|
|
|
|
|
); |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
28
|
|
|
|
|
|
|
sub configure { |
|
29
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $hash ) = @_; |
|
30
|
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
9
|
my $lm = $self->{lm}; |
|
32
|
1
|
|
|
|
|
3
|
my $rm = $self->{rm}; |
|
33
|
|
|
|
|
|
|
|
|
34
|
1
|
50
|
|
|
|
7
|
$lm = delete $hash->{lm} if exists $hash->{lm}; |
|
35
|
1
|
50
|
|
|
|
8
|
$lm = delete $hash->{leftmargin} if exists $hash->{leftmargin}; |
|
36
|
1
|
50
|
|
|
|
5
|
$rm = delete $hash->{rm} if exists $hash->{rm}; |
|
37
|
1
|
50
|
|
|
|
6
|
$rm = delete $hash->{rightmargin} if exists $hash->{rightmargin}; |
|
38
|
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
3
|
my $width = $rm - $lm; |
|
40
|
1
|
50
|
|
|
|
4
|
if ( $width < 1 ) { |
|
41
|
0
|
0
|
|
|
|
0
|
warn "Bad margins, ignored" if $^W; |
|
42
|
0
|
|
|
|
|
0
|
return; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
1
|
50
|
|
|
|
4
|
if ( $width < 20 ) { |
|
45
|
0
|
0
|
|
|
|
0
|
warn "Page probably too narrow" if $^W; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
5
|
for ( keys %$hash ) { |
|
49
|
0
|
0
|
|
|
|
0
|
warn "Unknown configure option '$_'" if $^W; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
3
|
$self->{lm} = $lm; |
|
53
|
1
|
|
|
|
|
3
|
$self->{rm} = $rm; |
|
54
|
1
|
|
|
|
|
3
|
$self; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
58
|
|
|
|
|
|
|
sub begin { |
|
59
|
9
|
|
|
9
|
0
|
16
|
my $self = shift; |
|
60
|
|
|
|
|
|
|
|
|
61
|
9
|
|
|
|
|
35
|
$self->SUPER::begin; |
|
62
|
9
|
|
|
|
|
30
|
$self->{curpos} = 0; # current output position. |
|
63
|
9
|
|
|
|
|
13
|
$self->{maxpos} = 0; # highest value of $pos (used by header underliner) |
|
64
|
9
|
|
|
|
|
26
|
$self->{hspace} = 0; # horizontal space pending flag |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
68
|
|
|
|
|
|
|
sub end { |
|
69
|
9
|
|
|
9
|
0
|
25
|
shift->collect("\n"); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
73
|
|
|
|
|
|
|
sub header_start { |
|
74
|
2
|
|
|
2
|
0
|
4
|
my ( $self, $level ) = @_; |
|
75
|
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
21
|
$self->vspace( 1 + ( 6 - $level ) * 0.4 ); |
|
77
|
2
|
|
|
|
|
5
|
$self->{maxpos} = 0; |
|
78
|
2
|
|
|
|
|
7
|
1; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
82
|
|
|
|
|
|
|
sub header_end { |
|
83
|
2
|
|
|
2
|
0
|
5
|
my ( $self, $level ) = @_; |
|
84
|
|
|
|
|
|
|
|
|
85
|
2
|
50
|
|
|
|
6
|
if ( $level <= 2 ) { |
|
86
|
2
|
|
|
|
|
3
|
my $line; |
|
87
|
2
|
100
|
|
|
|
7
|
$line = '=' if $level == 1; |
|
88
|
2
|
100
|
|
|
|
13
|
$line = '-' if $level == 2; |
|
89
|
2
|
|
|
|
|
7
|
$self->vspace(0); |
|
90
|
2
|
|
|
|
|
8
|
$self->out( $line x ( $self->{maxpos} - $self->{lm} ) ); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
2
|
|
|
|
|
7
|
$self->vspace(1); |
|
93
|
2
|
|
|
|
|
6
|
1; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
97
|
|
|
|
|
|
|
sub bullet { |
|
98
|
10
|
|
|
10
|
0
|
130
|
my $self = shift; |
|
99
|
|
|
|
|
|
|
|
|
100
|
10
|
|
|
|
|
40
|
$self->SUPER::bullet( $_[0] . ' ' ); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
104
|
|
|
|
|
|
|
sub hr_start { |
|
105
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
|
106
|
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
7
|
$self->vspace(1); |
|
108
|
1
|
|
|
|
|
14
|
$self->out( '-' x ( $self->{rm} - $self->{lm} ) ); |
|
109
|
1
|
|
|
|
|
4
|
$self->vspace(1); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
113
|
|
|
|
|
|
|
sub pre_out { |
|
114
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# should really handle bold/italic etc. |
|
117
|
1
|
50
|
|
|
|
4
|
if ( defined $self->{vspace} ) { |
|
118
|
1
|
50
|
|
|
|
4
|
if ( $self->{out} ) { |
|
119
|
1
|
|
|
|
|
7
|
$self->nl() while $self->{vspace}-- >= 0; |
|
120
|
1
|
|
|
|
|
3
|
$self->{vspace} = undef; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
1
|
|
|
|
|
3
|
my $indent = ' ' x $self->{lm}; |
|
124
|
1
|
|
|
|
|
2
|
my $pre = shift; |
|
125
|
1
|
|
|
|
|
8
|
$pre =~ s/^/$indent/mg; |
|
126
|
1
|
|
|
|
|
3
|
$self->collect($pre); |
|
127
|
1
|
|
|
|
|
3
|
$self->{out}++; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
131
|
|
|
|
|
|
|
sub out { |
|
132
|
787
|
|
|
787
|
0
|
946
|
my $self = shift; |
|
133
|
787
|
|
|
|
|
993
|
my $text = shift; |
|
134
|
|
|
|
|
|
|
|
|
135
|
787
|
|
|
|
|
1032
|
$text =~ tr/\xA0\xAD/ /d; |
|
136
|
|
|
|
|
|
|
|
|
137
|
787
|
100
|
|
|
|
2332
|
if ( $text =~ /^\s*$/ ) { |
|
138
|
389
|
|
|
|
|
551
|
$self->{hspace} = 1; |
|
139
|
389
|
|
|
|
|
927
|
return; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
398
|
100
|
|
|
|
884
|
if ( defined $self->{vspace} ) { |
|
143
|
32
|
100
|
|
|
|
68
|
if ( $self->{out} ) { |
|
144
|
25
|
|
|
|
|
114
|
$self->nl while $self->{vspace}-- >= 0; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
32
|
|
|
|
|
77
|
$self->goto_lm; |
|
147
|
32
|
|
|
|
|
57
|
$self->{vspace} = undef; |
|
148
|
32
|
|
|
|
|
51
|
$self->{hspace} = 0; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
398
|
100
|
|
|
|
829
|
if ( $self->{hspace} ) { |
|
152
|
358
|
100
|
|
|
|
737
|
if ( $self->{curpos} + length($text) > $self->{rm} ) { |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# word will not fit on line; do a line break |
|
155
|
41
|
|
|
|
|
78
|
$self->nl; |
|
156
|
41
|
|
|
|
|
76
|
$self->goto_lm; |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
else { |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# word fits on line; use a space |
|
161
|
317
|
|
|
|
|
781
|
$self->collect(' '); |
|
162
|
317
|
|
|
|
|
475
|
++$self->{curpos}; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
358
|
|
|
|
|
491
|
$self->{hspace} = 0; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
398
|
|
|
|
|
948
|
$self->collect($text); |
|
168
|
398
|
|
|
|
|
642
|
my $pos = $self->{curpos} += length $text; |
|
169
|
398
|
100
|
|
|
|
866
|
$self->{maxpos} = $pos if $self->{maxpos} < $pos; |
|
170
|
398
|
|
|
|
|
971
|
$self->{'out'}++; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
174
|
|
|
|
|
|
|
sub goto_lm { |
|
175
|
103
|
|
|
103
|
0
|
119
|
my $self = shift; |
|
176
|
|
|
|
|
|
|
|
|
177
|
103
|
|
|
|
|
138
|
my $pos = $self->{curpos}; |
|
178
|
103
|
|
|
|
|
127
|
my $lm = $self->{lm}; |
|
179
|
103
|
100
|
|
|
|
248
|
if ( $pos < $lm ) { |
|
180
|
73
|
|
|
|
|
85
|
$self->{curpos} = $lm; |
|
181
|
73
|
|
|
|
|
256
|
$self->collect( " " x ( $lm - $pos ) ); |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
186
|
|
|
|
|
|
|
sub nl { |
|
187
|
92
|
|
|
92
|
0
|
119
|
my $self = shift; |
|
188
|
|
|
|
|
|
|
|
|
189
|
92
|
|
|
|
|
120
|
$self->{'out'}++; |
|
190
|
92
|
|
|
|
|
115
|
$self->{curpos} = 0; |
|
191
|
92
|
|
|
|
|
217
|
$self->collect("\n"); |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
195
|
|
|
|
|
|
|
sub adjust_lm { |
|
196
|
30
|
|
|
30
|
0
|
37
|
my $self = shift; |
|
197
|
|
|
|
|
|
|
|
|
198
|
30
|
|
|
|
|
46
|
$self->{lm} += $_[0]; |
|
199
|
30
|
|
|
|
|
55
|
$self->goto_lm; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
203
|
|
|
|
|
|
|
sub adjust_rm { |
|
204
|
2
|
|
|
2
|
0
|
5
|
shift->{rm} += $_[0]; |
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
__END__ |