Created
May 12, 2017 18:54
-
-
Save luissardon/c893c55cdee78391c7ca70966c36f1af to your computer and use it in GitHub Desktop.
Remove HTML entities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: http://stackoverflow.com/a/13091266 | |
function decode_entities(value) { | |
var element = document.createElement('div'); | |
function decode_HTML_entities (str) { | |
if (str && typeof str === 'string') { | |
// Escape HTML before decoding for HTML Entities | |
str = escape(str).replace(/%26/g,'&').replace(/%23/g,'#').replace(/%3B/g,';'); | |
element.innerHTML = str; | |
if (element.innerText) { | |
str = element.innerText; | |
element.innerText = ''; | |
} else { | |
// Firefox support | |
str = element.textContent; | |
element.textContent = ''; | |
} | |
} | |
return unescape(str); | |
} | |
return decode_HTML_entities(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment