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;
21 %stripper = ( parser => HTML::Parser->new );
23 $stripper{parser}->handler(text => sub { $stripper{text} .= $_[1]; });
27 $stripper{parser}->parse($value);
28 $stripper{parser}->eof;
30 $stripper{text} =~ s{\&([^;]+);}{ $entities{$1} || "\&$1;" }eg;
32 return delete $stripper{text};
44 SL::HTML::Util - Utility functions dealing with HTML
48 my $plain_text = SL::HTML::Util->strip('<h1>Hello World</h1>');
54 =item C<strip $html_content>
56 Removes all HTML elements and tags from C<$html_content> and returns
57 the remaining plain text.
67 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>