This is still not great code but at least somewhat an improvement. Tests were expanded to showcase the new behavior.
I think, ideally, we would append opening/closing tags to the ancestor p or li node's cdata as soon as we encounter the start/end of an em or code element. This would then also handle empty elements correctly.
Three commits:
Improve handling of \<em> and \<code> tags
This is still not great code but at least somewhat an improvement. Tests were expanded to showcase the new behavior.
I think, ideally, we would append opening/closing tags to the ancestor
p
orli
node's cdata as soon as we encounter the start/end of anem
orcode
element. This would then also handle empty elements correctly.