in reply to Re: Re: Fixing Bad HTML
in thread Fixing Bad HTML

Though I'd be inclined to disallow sloppy markup like this (as others have suggested), one option I've used in the past is to backtrack up the stack looking for a matching tag and autoclosing any open tags I pass along the way.

In this case that would proceed something like this. You get to the </B> and look at the tag at the top of the stack. It's not a <B>, it's an <I>, so you generate a </I> yourself and pop that off the stack, then try again. This time it is a <B> so you can just pop it off the top and you move on.

The next closing tag is </I>. Since there's no matching open tag on the stack, you simply remove it.

        $perlmonks{seattlejohn} = 'John Clyman';