Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Truncating HTML early

by nop (Hermit)
on Mar 18, 2002 at 18:59 UTC ( [id://152558]=note: print w/replies, xml ) Need Help??


in reply to Truncating HTML early

Thanks, all for your excellent suggestions.

While working on this today, I had yet another idea, so I thought I'd share it here.

later edit by nop:
the following suggestion was not a good one --
leaving in empty tags creates HTML littered with empty bulleted lists, etc.
yuck.
my final solution was to stop taking text after some limit of words, then use tidy to clean out the empty tags.

original post:
Assuming there's much text relative to markup, and assuming the markup is reasonably well-formed, an easy solution to this problem using HTML::Parser is count words in the text handler, and when that count exceeds a limit, have the handler stop appending new text to the result string. Allow the start and end handlers to continue adding their tags. The idea here is that when the text limit is reached, the rest of the markup (probably not much) will flow out empty.

This wouldn't be a good solution for html with heavy markup, but I think it may work in my case.......

nop

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found