Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: substr(ingifying) htmlized text

by bprew (Monk)
on Sep 23, 2005 at 19:55 UTC ( [id://494651]=note: print w/replies, xml ) Need Help??


in reply to substr(ingifying) htmlized text

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:

<font>some stuff <h3>some more</font> stuff</h3>

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.
See HTML::Validator or HTML::Tidy or even HTML::TokeParser::Simple.

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.

Replies are listed 'Best First'.
Re^2: substr(ingifying) htmlized text
by punkish (Priest) on Sep 23, 2005 at 21:09 UTC
    For example, if you were given this piece of HTML:
    <font>some stuff <h3>some more</font> stuff</h3>
    You are absolutely correct. However, I won't face that problem because I am creating the html in the first place (see my update to the OP).
    --

    when small people start casting long shadows, it is time to go to bed

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-26 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found