| Line | |
|---|
| 1 | package SVN::TracWiki::Plugin::Extract; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use base qw( File::Extract SVN::TracWiki::Plugin Class::Data::Inheritable ); |
|---|
| 6 | |
|---|
| 7 | sub ext { } |
|---|
| 8 | sub mime_type { } |
|---|
| 9 | sub extract { } |
|---|
| 10 | sub format { } |
|---|
| 11 | |
|---|
| 12 | sub 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 | |
|---|
| 37 | 1; |
|---|