Strip(3pm)
π Strip(3pm) β HTML::Strip π
okay bestie, gather round, because this is HTML::Strip, a little Perl module living in the perl manual pages under User Contributed Perl Documentation, and it is here to strip HTML markup from text fast and with zero manners. π
β¨ NAME β¨
HTML::Strip β Perl extension for stripping HTML markup from text. that's it. that's the whole job description. π
πΈ SYNOPSIS πΈ
use HTML::Strip;
my $hs = HTML::Strip->new();
my $clean_text = $hs->parse( $raw_html );
$hs->eof;
look at that. four lines. clean, gorgeous, iconic. π
π¦ DESCRIPTION π¦
This module simply strips HTML-like markup from text rapidly and brutally. like, no hesitation, no apologies. It could easily be used to strip XML or SGML markup instead β but since removing HTML is a much more common problem, this module lives in the HTML:: namespace. makes sense, it's giving practical. β¨
It's written in XS, so it's about five times quicker than using regular expressions for the same task. no cap. π₯
It does not do any syntax checking. if that's what you want, go use HTML::Parser, bestie, this is not that girl. Instead it merely applies the following rules:
- 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:
Quote β Quotes are considered to start with either a ' or a " character, and end with a matching character not preceded by an even number or escaping slashes (i.e. "\"" does not end the quote but "\\\\"" does).
Comment β If the tag starts with an exclamation mark, it is assumed to be a declaration or a comment. Within such tags, > characters do not end the tag if they appear within pairs of double dashes (e.g. <!-- <a href="old.htm">old page</a> --> would be stripped completely). No parsing for quotes is performed within comments, so for instance <!-- comment with both ' quote types " --> would be entirely stripped.
- Anything that appears between tags which we term strip tags is removed. By default, these tags are
title,script,styleandapplet. π
HTML::Strip maintains state between calls, so you can parse a document in chunks should you wish. If a call to parse() ends half-way through a tag, quote or comment; the next call to parse() expects its input to carry on from that point. it's literally picking up where it left off, main character energy. π«Ά
If this is not the behaviour you want, you can either call eof() between calls to parse(), or set auto_reset to true (either on the constructor or with set_auto_reset) so that the parser will reset after each call.
π METHODS π
new()β Constructor. Can optionally take a hash of settings (with keys corresponding to theset_methods below).
Example:
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_emit_newlines()β Takes a boolean value. If set to true, HTML::Strip will output newlines after<br>and<p>tags. Set to false by default.set_decode_entities()β Takes a boolean value. If set to false, HTML::Strip will not decode HTML entities. Set to true by default.filter_entities()β If HTML::Entities is available, this method behaves just like invokingHTML::Entities::decode_entities, except that it respects the current setting ofdecode_entities.set_filter()β Sets a filter to be applied after tags were stripped. It may accept the name of a method (likefilter_entities) or a code ref. By default, its value isfilter_entitiesif HTML::Entities is available orundefotherwise.set_auto_reset()β Takes a boolean value. If set to true,parseresets after each call (equivalent to callingeof). Otherwise, the parser remembers its state from one call toparseto another, until you calleofexplicitly. 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.
π LIMITATIONS π
π 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.
β EXPORT β
None by default. not one thing. zero. nada. π«Ά
π AUTHOR π
Alex Bowley <kilinrax@cpan.org>
π§ SEE ALSO π§
perl, HTML::Parser, HTML::Entities
π LICENSE π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. slay, honestly.
and that's the whole thing, bestie βperl v5.42.3, dated2026-08-20. go forth and strip. πβ¨πΈ
π¦ where this page comes from
- ubuntu stonking: libhtml-strip-perl 2.12-1build5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms