my (blush) HTML::TagFilter is written with this in mind. it's just a subclass of HTML::Parser, and as always there are many other ways to do it. Many here would probably recommend building a screen of your own on HTML::TokeParser. Ymmv.

TagFilter is very young (0.08 or so), and pulls in quite a lot of cpan with it (all the cleverness is in the Parser), but it's meant to be very easy to use. to eliminate all html from input, you would just need to do this:

use HTML::TagFilter; my $dirty_text = ...; #something from input my $tf = HTML::TagFilter->new(); $tf->allow_tags(); my $clean_text = $tf->filter($dirty_text);

and to allow formatting html but disallow images and links (and strip out javascript from other tags):

use HTML::TagFilter; my $dirty_text = ...; #something from input my $tf = HTML::TagFilter->new(); $tf->deny_tags({ img=> {all => []}, a => {all => []}, }); my $clean_text = $tf->filter($dirty_text);

(images and links are let through by default, so a couple of rules must be added to eliminate them).

and so on. but getting this right requires a lot of attention to browser behaviour. it's amazing what range of things explorer will interpret as an instruction, for example, and i'm always trying to keep up. best to be very restrictive to begin with and only relax the restrictions with great care.

ps. new version soon, honest.


In reply to Re: Stopping the abuse by thpfft
in thread Stopping the abuse by rezoraith

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.