As nelsa pointed out, copying/pasting HTML into the WYSIWYG editor is not satisfactory because it can produce alternative HTML, different from what you've pasted, which may create invalid tag syntax. For instance, it might enter a paragraph inside a tag and produce something like "{%<p> if invoice.status == 'active' %}</p>". This is not visible except when viewing the Source, so it is always best to make direct HTML changes while in Source mode. I presumed the OP's issue was experienced with default templates, but I'm more convinced this is the cause instead.