Nodejs HTML Decode decodeHtml()

Here you can find the source of decodeHtml()

Method Source Code

// decode an html encoded string
String.prototype.decodeHtml = function () {
    var string = new String(this);
    /*w ww. ja v  a2s. c o  m*/
    string = string.replace(/&lt;/g, "<");
    string = string.replace(/&gt;/g, ">");
    string = string.replace(/&quot;/g,  "\"")
    string = string.replace(/&39;/g,  "'");
    string = string.replace(/&amp;/g, "&");
    
    return string
}

Related

  1. htmlDecode(value)
    function htmlDecode(value)
        if(value)
            return $("<div />").html(value).text();
        else
            return '';
    ...
    
  2. htmlDecode()
    String.prototype.htmlDecode = function() {
      return this.replace(/\&amp\;/g, '\&').replace(/\&gt\;/g, '\>').replace(
          /\&lt\;/g, '\<').replace(/\&quot\;/g, '\'').replace(/\&\#39\;/g,
          '\'');
    };
    
  3. htmlDecode()
    String.prototype.htmlDecode = function () {
        var div = document.createElement('div');
        div.innerHTML = this;
        return div.innerText || div.textContent;
    };
    
  4. decodeHtmlEntity()
    String.prototype.decodeHtmlEntity = function(){
        var ta = document.createElement('textarea');
        ta.innerHTML = this;
        return ta.value;
    };