Skip to content

Instantly share code, notes, and snippets.

@luissardon
Created May 12, 2017 18:54
Show Gist options
  • Save luissardon/c893c55cdee78391c7ca70966c36f1af to your computer and use it in GitHub Desktop.
Save luissardon/c893c55cdee78391c7ca70966c36f1af to your computer and use it in GitHub Desktop.
Remove HTML entities
// 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