When a namespace is used - particularly the HTML legacy namespace, or an incorrect XHTML namespace - then the resulting HTML can be a bit odd. This is most obvious when using nested structures such as tables.
The issue is caused by a bug in the code used to recognise foreign markup, which is bypassed when looking up the previous tag.
Fixed.