Added in logic to deal with html rendering of nested elements

There was a bug where nested html elements, eg <div><form><div>....</div></form></div>, were rendering too early at the first
closing tag, eg <div><form><div>....</div>