Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Cleaning up HTML

by clinton (Priest)
on Apr 22, 2008 at 09:51 UTC ( #682124=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Cleaning up HTML
in thread Cleaning up HTML

I've been trying some things with this module, and it's a bit hard going.

Agreed - it makes certain things very easy, but other bits (like adding allowed attributes) are nasty and crust. As we've discussed privately, this module could do with a major API overhaul. And a new name! Stripping scripts is just a part of what this does. It's actually a very powerful HTML tidier

I'd like to combine the two span tags, merging their style attributes:

Merging adjacent tags wasn't a use that I envisaged, but that was my own lack of imagination - the next version will have some nice way of querying the parent and sibling elements.

I've been trying to think about how you could do this with the current module (using private methods and properties), but it's nasty, and would probably result in having to reparse content, because to merge two spans, you need to know:

  • that the child span HAS content
  • the the parent span has NO content
  • but you don't know that until you're finished with the parent span because it's a stream parser
  • by which time, the child span has been converted to text

As per the private message you've just sent me, maintaining the nodes as a DOM-tree seems like the only reasonable way to handle this.

UPDATE So if we're planning on building DOM-trees, this starts sounding like a job for XML::LibXML, or HTML::TreeBuilder. But HTML::StripScripts does three things that neither of these modules does (AFAIK):

  • it understands the meaning and context of tags, so that it can figure out that lone <li> elements cannot exist outside <ul> or <ol>
  • it provides a mechanism for parsing / allowing / disallowing attribute and CSS style declarations
  • it cleans up XSS attacks

Ideas for the new glamorous DOM-tree based version gladly accepted


Comment on Re^3: Cleaning up HTML
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://682124]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-12-20 16:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (96 votes), past polls