Anything that looks like a tag, or group of tags will be replaced with
a single space character. Tags are considered to be anything that
starts with a < and ends with a >; with the caveat that a
> character may appear in either of the following without
ending the tag:
|2.||Anything the appears within so-called strip tags is stripped as well. By default, these tags are title, script, style and applet.|
If this is not going to be the case, be sure to call $hs->eof() between calls to $hs->parse(). Alternatively, you may set auto_reset to true on the constructor or any time after with set_auto_reset, so that the parser will always operate in one-shot basis (resetting after each parsed chunk).
new() Constructor. Can optionally take a hash of settings (with keys corresponsing to the set_ methods below).
For example, the following is a valid constructor:
my $hs = HTML::Strip->new( striptags => [ script, iframe ], emit_spaces => 0 );
parse() Takes a string as an argument, returns it stripped of HTML. eof() Resets the current state information, ready to parse a new block of HTML. clear_striptags() Clears the current set of strip tags. add_striptag() Adds the string passed as an argument to the current set of strip tags. set_striptags() Takes a reference to an array of strings, which replace the current set of strip tags. set_emit_spaces() Takes a boolean value. If set to false, HTML::Strip will not attempt any conversion of tags into spaces. Set to true by default. set_decode_entities() Takes a boolean value. If set to false, HTML::Strip will decode HTML entities. Set to true by default. filter_entities() If HTML::Entities is available, this method behaves just like invoking HTML::Entities::decode_entities, except that it respects the current setting of decode_entities. set_filter() Sets a filter to be applied after tags were stripped. It may accept the name of a method (like filter_entities) or a code ref. By default, its value is filter_entities if HTML::Entities is available or undef otherwise. set_auto_reset() Takes a boolean value. If set to true, parse resets after each call (equivalent to calling eof). Otherwise, the parser remembers its state from one call to parse to another, until you call eof explicitly. Set to false by default. set_debug() Outputs extensive debugging information on internal state during the parse. Not intended to be used by anyone except the module maintainer. decode_entities() filter() auto_reset() debug() Readonly accessors for their respective settings.
Whitespace Despite only outputting one space character per group of tags, and avoiding doing so when tags are bordered by spaces or the start or end of strings, HTML::Strip can often output more than desired; such as with the following HTML:
<h1> HTML::Strip </h1> <p> <em> <strong> fast, and brutal </strong> </em> </p>
Which gives the following output:
HTML::Strip fast, and brutal
Thus, you may want to post-filter the output of HTML::Strip to remove excess whitespace (for example, using tr/ / /s;). (This has been improved since previous releases, but is still an issue)
HTML Entities HTML::Strip will only attempt decoding of HTML entities if HTML::Entities is installed.
None by default.
Alex Bowley <email@example.com>
perl, HTML::Parser, HTML::Entities
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|perl v5.20.3||STRIP (3)||2015-01-05|