Please add the following line to remove all html elements in "theSelection":
theSelection = theSelection.replace(/<[^>]*>/ig, '');
(please add it on line 207)
In my case does a meta network rewrite my links.
The function doesn't work correctly anymore (you have html in the quoted message) because html are automatically inserted (all links will be rewritten -> also in the hidden message_element).