root/lang/perl/SVN-TracWiki/trunk/lib/SVN/TracWiki/Plugin/Extract.pm @ 9

Revision 9, 0.7 kB (checked in by mizzy, 6 years ago)

SVN::TracWiki: imported.

Line 
1package SVN::TracWiki::Plugin::Extract;
2
3use strict;
4use warnings;
5use base qw( File::Extract SVN::TracWiki::Plugin Class::Data::Inheritable );
6
7sub ext { }
8sub mime_type { }
9sub extract { }
10sub format { }
11
12sub strip_html {
13    my ($self, $html ) = @_;
14
15    eval {
16        require HTML::FormatText;
17        require HTML::TreeBuilder;
18    };
19
20    if ($@) {
21        # dump stripper
22        $html =~ s/<[^>]*>//g;
23        return HTML::Entities::decode($html);
24    }
25
26    my $tree = HTML::TreeBuilder->new;
27    $tree->parse($html);
28    $tree->eof;
29
30    my $formatter = HTML::FormatText->new(leftmargin => 0);
31    my $text = $formatter->format($tree);
32#    utf8::decode($text);
33    $text =~ s/\s*$//s;
34    $text;
35}
36
371;
Note: See TracBrowser for help on using the browser.