line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormatText::Html2textPY; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25121
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'HTML::FormatExternal'; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1108
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
71002
|
use MRO::Compat; |
|
1
|
|
|
|
|
2778
|
|
|
1
|
|
|
|
|
11
|
|
9
|
1
|
|
|
1
|
|
24
|
use mro 'c3'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
45
|
use constant DEFAULT_LEFTMARGIN => 0; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
14
|
1
|
|
|
1
|
|
5
|
use constant DEFAULT_RIGHTMARGIN => 79; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
15
|
1
|
|
|
1
|
|
4
|
use constant _WIDE_CHARSET => 'iso-8859-1'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
273
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
HTML::FormatText::Html2textPY - format HTML as plain text using html2text python script |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use HTML::FormatText::Html2textPY; |
24
|
|
|
|
|
|
|
$text = HTML::FormatText::Html2textPY->format_file ($filename); |
25
|
|
|
|
|
|
|
$text = HTML::FormatText::Html2textPY->format_string ($html_string); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$formatter = HTML::FormatText::Html2textPY->new; |
28
|
|
|
|
|
|
|
$tree = HTML::TreeBuilder->new_from_file ($filename); |
29
|
|
|
|
|
|
|
$text = $formatter->format ($tree); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#if you don't want wrapping do this |
32
|
|
|
|
|
|
|
$formatter = HTML::FormatText::Html2textPY->new( rightmargin => -1 ); |
33
|
|
|
|
|
|
|
$formatter->format_string ($html_string); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
C turns HTML into plain text using the |
38
|
|
|
|
|
|
|
C python script. Please make sure you have it installed before |
39
|
|
|
|
|
|
|
using this package. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub program_full_version { |
44
|
0
|
|
|
0
|
1
|
|
my ( $self_or_class ) = @_; |
45
|
0
|
|
|
|
|
|
return $self_or_class->_run_version ( [ 'html2text', '--version' ], '2>&1' ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub program_version { |
49
|
0
|
|
|
0
|
1
|
|
my ( $self_or_class ) = @_; |
50
|
0
|
|
|
|
|
|
my $version = $self_or_class->program_full_version; |
51
|
0
|
0
|
|
|
|
|
if (! defined $version) { return undef; } |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
$version =~ /^html2text (.*)/ or $version =~ /^(.*)/; |
54
|
0
|
|
|
|
|
|
return $1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _make_run { |
58
|
0
|
|
|
0
|
|
|
my ( $class, $input_filename, $options ) = @_; |
59
|
0
|
|
|
|
|
|
my @command; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#turn wrapping off if right margin is set to < 0 in caller |
62
|
0
|
0
|
|
|
|
|
if ( $class->{rightmargin} < 0 ) { |
63
|
0
|
|
|
|
|
|
@command = ( 'html2text', '--body-width=0' ); |
64
|
|
|
|
|
|
|
} else { |
65
|
0
|
|
|
|
|
|
@command = ( 'html2text' ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return ( \@command, '<', $input_filename ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SEE ALSO |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
L |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 AUTHOR |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Alex Pavlovic, C |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 COPYRIGHT |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Copyright (c) 2013 |
82
|
|
|
|
|
|
|
the HTML::FormatText::Html2textPY L |
83
|
|
|
|
|
|
|
as listed above. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 LICENSE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it |
88
|
|
|
|
|
|
|
under the same terms as Perl itself. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |