Last modified: 2014-01-13 17:31:37 UTC
My first guess is that Tidy is the culprit. Try the input <ref>foo</ref><ref><div>bar</div></ref><ref><table><tr><td>baz</td></tr></table></ref> <references /> on Wikipedia. The first reference is correctly wrapped in a <span class="reference-text">, in the second reference this span is moved inside the <div>, in the third it is missing completely.
You are putting HTML block elements into inline elements. Tidy is rightfully cleaning up.
Marking bug 38661 as a duplicate of the more specific and more commented bug 47544. Whats described here is an effect of the bad HTML nesting described in bug 47544. *** This bug has been marked as a duplicate of bug 47544 ***