line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::HtmlToText;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
46369
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw( @ISA $VERSION );
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
5
|
1
|
|
|
1
|
|
6
|
use base qw( Template::Plugin );
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
1244
|
|
6
|
1
|
|
|
1
|
|
8605
|
use Template::Plugin;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
360
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = '0.03';
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new {
|
11
|
0
|
|
|
0
|
1
|
|
my ($class, $context, $arg) = @_;
|
12
|
0
|
|
|
|
|
|
$context->define_filter('html2text', [ \&html2text => 1 ]);
|
13
|
0
|
|
|
|
|
|
return \&tt_wrap;
|
14
|
|
|
|
|
|
|
}
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub html2text {
|
17
|
0
|
|
|
0
|
0
|
|
my ($context, $args) = @_;
|
18
|
|
|
|
|
|
|
return sub {
|
19
|
0
|
|
|
0
|
|
|
my $html = shift;
|
20
|
0
|
0
|
|
|
|
|
return $html unless ($html =~ m#(<|>)#s);
|
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
require HTML::TreeBuilder;
|
23
|
0
|
|
|
|
|
|
my $tree = HTML::TreeBuilder->new->parse($html);
|
24
|
0
|
|
|
|
|
|
require HTML::FormatText;
|
25
|
0
|
|
|
|
|
|
my $formatter = HTML::FormatText->new(%{$args});
|
|
0
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $text = $formatter->format($tree);
|
27
|
0
|
|
|
|
|
|
return $text;
|
28
|
|
|
|
|
|
|
}
|
29
|
0
|
|
|
|
|
|
}
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
1;
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__END__
|