Skip to content

Instantly share code, notes, and snippets.

@loicbisiere
Created November 15, 2017 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loicbisiere/b5dec1c8b8e8a06bb8008dd43f380543 to your computer and use it in GitHub Desktop.
Save loicbisiere/b5dec1c8b8e8a06bb8008dd43f380543 to your computer and use it in GitHub Desktop.
String.prototype.decodeHTML = function() {
var map = {"gt":">" /* , … */};
return this.replace(/&(#(?:x[0-9a-f]+|\d+)|[a-z]+);?/gi, function($0, $1) {
if ($1[0] === "#") {
return String.fromCharCode($1[1].toLowerCase() === "x" ? parseInt($1.substr(2), 16) : parseInt($1.substr(1), 10));
} else {
return map.hasOwnProperty($1) ? map[$1] : $0;
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment