Clear questions and runnable code
get the best and fastest answer
Re: Truncating HTML earlyby nop (Hermit)
|on Mar 18, 2002 at 18:59 UTC||Need Help??|
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.
my final solution was to stop taking text after some limit of words, then use tidy to clean out the empty tags.
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.......