Nodejs HTML Unescape unescapeHtml()

Here you can find the source of unescapeHtml()

Method Source Code

/*/*  w w w . j a v a2  s .  c  o  m*/
 * Copyright (C) 2011 Tony.Ni, Jim.Jiang http://mobilelite.org.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


String.prototype.unescapeHtml = function () {
    var temp = document.createElement("div");
    temp.innerHTML = this;
    var result = temp.childNodes[0].nodeValue;
    temp.removeChild(temp.firstChild);
    return result;
}

Related

  1. unescapeEntities()
    String.prototype.unescapeEntities = function() {
      return this.replace(/&#([0-9]{1,4});/gi, function(match, numStr) {
        var num = parseInt(numStr, 10);
        return String.fromCharCode(num);
      });
    };
    
  2. unescapeHTML()
    String.prototype.unescapeHTML = function() {
      return String(this).replace("&amp;", "&").replace("&lt;", "<").replace("&gt;", ">").replace('&quot;', '"').replace('&#39;', "'").replace('&#x2F;', "/");
    
  3. unescapeHtml()
    String.prototype.unescapeHtml = function () {
        var temp = document.createElement("div");
        temp.innerHTML = this;
        var result = temp.childNodes.length === 0 ? "" : temp.childNodes[0].nodeValue;
        if(temp.firstChild) temp.removeChild(temp.firstChild);
        return result;
    };
    
  4. unescapeHtml()
    String.prototype.unescapeHtml = function () {
      var temp = document.createElement("div");
      temp.innerHTML = this;
      var result = "";
      for (var i = 0; i < temp.childNodes.length; i++) {
       result = result + temp.childNodes[i].nodeValue;
      temp.removeChild(temp.firstChild)
      return result;
    ...
    
  5. unescapeHtml()
    String.prototype.unescapeHtml = function () {
        var temp = document.createElement("div");
        temp.innerHTML = this;
        var result = temp.childNodes.length === 0 ? "" : temp.childNodes[0].nodeValue;
        if(temp.firstChild) temp.removeChild(temp.firstChild);
        return result;
    };
    
  6. unescapeHtmlEntities()
    String.prototype.unescapeHtmlEntities = function () {
      try{
        var temp = document.createElement('textarea');
        temp.innerHTML = this;
        return temp.value;
      }catch(e){
        return this;
    
  7. unescapeHtmlEntities()
    String.prototype.unescapeHtmlEntities = function () {
      try{
        var temp = document.createElement('textarea');
        temp.innerHTML = this;
        return temp.value;
      }catch(e){
        return this;