@borjasalguero If i restore a tag this leads to the problem of nested <a> tags which are invalid HTML. I discussed this problem in detail while answering @rwldrn query to avoid using innerHTML more than once.
to re-iterate the problem was the anchor tags which are added for url/email themselves was leading to nesting, which was leading to DOM modifying the html itself when innerHTML was being assigned to.