in reply to Dynamically cleaning up HTML fragments
>>We should reject tags that do not have certain mandatory attibutes. No "a" without an href for example.
Local anchors do not have "href" as an attribute, they have a "name", eg <a name="local page anchor">here</a> ;)
Are you familiar with the event driven HTML::Parser? I have not used it to clean invalid source, but here's an idea (eg): when your start tag handler hits an img tag, put the entire tag text into an otherwise null global. In both the end and start tag handler, you check this global for content; if the img is not closed add / to it.
Alternately, I can tell you for a fact that HTML::Parser treats / used XHTMLishly (ie, not the first character in the tag) as an attribute. Therefore, with tags like image you can check for the / attribute and if not present, do the edit.
The rest of your requirements -- stripping certain tags, working with attributes, checking for text inside p tags, etc. -- can also easily be accomplished via HTML::Parser, but you will have to write some code to do it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Dynamically cleaning up HTML fragments
by Anonymous Monk on Sep 24, 2010 at 01:04 UTC | |
by SilasTheMonk (Chaplain) on Sep 24, 2010 at 15:23 UTC |