Hello,
OK, now we understand the exact issue. It wasn't a Tidy issue, but the content that was being added (we misunderstood the code). Replacing and adding HTML require using at least one tag to wrap the content; to use plain strings without HTML we recommend using replaceVariableByText.
Regards.