[SalesForce] How to de normalize text saved in a text area with HTML tags

I have an object that I've entered text with HTML snippets that I want to insert into a page using JavaScript. When the string is passed in the object(s) using Apex, the strings are normalized so that the < character is replaced with &lt; and the > character is replaced with &gt;. I'd like to covert them back and add them using the element.innerHTML property but I'm having issues translating the &lt; back to a <.

Anyone have any ideas?

Best Answer

If you cannot make it in Apex, you can try doing it in JavaScript instead:

function unescapeHtml(escapedString) {
    return escapedString
        .replace(/&amp;/g, "&")
        .replace(/&lt;/g, "<")
        .replace(/&gt;/g, ">")
        .replace(/&quot;/g, "\"")
        .replace(/&#039;/g, "'");