X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/3fbb0b9bbc37dbbe10407a858c58148e2d835c2c..792ae733e8f54eca6d306ad523a7a6e166fcb0e0:/SL/HTML/Util.pm diff --git a/SL/HTML/Util.pm b/SL/HTML/Util.pm new file mode 100644 index 000000000..7212d646f --- /dev/null +++ b/SL/HTML/Util.pm @@ -0,0 +1,62 @@ +package SL::HTML::Util; + +use strict; +use warnings; + +use HTML::Parser; + +my %stripper; + +sub strip { + my ($class_or_value) = @_; + + my $value = !ref($class_or_value) && (($class_or_value // '') eq 'SL::HTML::Util') ? $_[1] : $class_or_value; + + if (!%stripper) { + %stripper = ( parser => HTML::Parser->new ); + + $stripper{parser}->handler(text => sub { $stripper{text} .= $_[1]; }); + } + + $stripper{text} = ''; + $stripper{parser}->parse($value); + $stripper{parser}->eof; + + return delete $stripper{text}; +} + +1; +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::HTML::Util - Utility functions dealing with HTML + +=head1 SYNOPSIS + + my $plain_text = SL::HTML::Util->strip('

Hello World

'); + +=head1 FUNCTIONS + +=over 4 + +=item C + +Removes all HTML elements and tags from C<$html_content> and returns +the remaining plain text. + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut