1 package SL::HTML::Util;
16 my ($class_or_value) = @_;
18 my $value = !ref($class_or_value) && (($class_or_value // '') eq 'SL::HTML::Util') ? $_[1] : $class_or_value;
20 return '' unless $value;
23 %stripper = ( parser => HTML::Parser->new );
25 $stripper{parser}->handler(text => sub { $stripper{text} .= $_[1]; });
29 $stripper{parser}->parse($value);
30 $stripper{parser}->eof;
32 $stripper{text} =~ s{\&([^;]+);}{ $entities{$1} || "\&$1;" }eg;
34 return delete $stripper{text};
46 SL::HTML::Util - Utility functions dealing with HTML
50 my $plain_text = SL::HTML::Util->strip('<h1>Hello World</h1>');
56 =item C<strip $html_content>
58 Removes all HTML elements and tags from C<$html_content> and returns
59 the remaining plain text.
69 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>