I don't have suggestions on doing the truncating, but whatever method you've chosen, you can send the resulting output into an instance of my
HTML::Lint object and validate that it's still well-formed.
xoxo,
Andy
--
<megaphone>
Throw down the gun and tiara and come out of the float!
</megaphone>