more useful options | |
PerlMonks |
Re: substr(ingifying) htmlized textby bprew (Monk) |
on Sep 23, 2005 at 19:55 UTC ( [id://494651]=note: print w/replies, xml ) | Need Help?? |
It sounds like you're more interested in writing a function that acts as a limited HTML parser/validator, is there a reason that you don't want to use an existing HTML parser/validator? Barring being able to use existing code... your psuedo-code sounds reasonable, if you're not looking for a >90% solution. Although, parsing HTMl is not easy, as the many lines on HTML parsers on CPAN attest to, so depending on how loose you want your outgoing HTML to be, it might be possible to write it in a function. Also, the hard part with HTML is always the edge cases, and you have to work under the assumption that no one else knows how to write HTML and all their HTML is "sketchy" at best. For example, if you were given this piece of HTML:
Your function would have no tags left over, at least according to the psuedo-code, even though this may not be valid HTML. It depends on how close to valid HTML you want to get. If you have a specific need, then rolling your own is probably a good idea. However, if you are just looking to try and make HTML more valid... there are probably solutions out there for you.
Also, I would be more explicit about what happens when you find a closing tag with no appropriate opening tag. My guess is that you'll just throw it away, but its something to think about.
In Section
Seekers of Perl Wisdom
|
|