Returns the given HTML with ampersands,
    quotes and angle brackets encoded.
483007
def escape(html, force=False):
    """"""
    if hasattr(html, '__html__') and not force:
        return html
    if html in NOTHING:
        return ''
    else:
        return to_string(html).replace('&', '&amp;').replace(
            '<', '&lt;').replace('>', '&gt;').replace("'", '&#39;').replace(
            '"', '&quot;')
1205365
function htmlToText(html) {
    var pos = html.indexOf('&');
    if (pos < 0) { return html; }
    // Handle numeric entities specially.  We can't use functional substitution
    // since that doesn't work in older versions of Safari.
    // These should be rare since most browsers convert them to normal chars.
    for (--pos; (pos = html.indexOf('&#', pos + 1)) >= 0;) {
      var end = html.indexOf(';', pos);
      if (end >= 0) {
        var num = html.substring(pos + 3, end);
        var radix = 10;
        if (num && num.charAt(0) === 'x') {
          num = num.substring(1);
          radix = 16;
        }
        var codePoint = parseInt(num, radix);
        if (!isNaN(codePoint)) {
          html = (html.substring(0, pos) + String.fromCharCode(codePoint) +
                  html.substring(end + 1));
        }
      }
    }

    return html.replace(pr_ltEnt, '<')
        .replace(pr_gtEnt, '>')
        .replace(pr_aposEnt, "'")
        .replace(pr_quotEnt, '"')
        .replace(pr_nbspEnt, ' ')
        .replace(pr_ampEnt, '&');
  }
1245665
public static String extractText(String html) {
        //return Jsoup.parse(text).text();
        html = replaceImgWithAlt(html);
        html = safeRemoveAllTags(html);
        
        html = unescapeHtml(html);
        
        return html;
    }
394072
public static String unescapeHtml(String s) {
    int amp = s.indexOf('&');
    if (amp < 0) { // Fast path.
      return s;
    }
    int n = s.length();
    StringBuilder sb = new StringBuilder(n);
    int pos = 0;
    do {
      // All numeric entities and all named entities can be represented in less than 12 chars, so
      // avoid any O(n**2) problem on "&&&&&&&&&" by not looking for ; more than 12 chars out.
      int end = -1;
      int entityLimit = Math.min(n, amp + 12);
      for (int i = amp + 1; i < entityLimit; ++i) {
        if (s.charAt(i) == ';') {
          end = i + 1;
          break;
        }
      }
      int cp = -1;
      if (end == -1) {
        cp = -1;
      } else {
        if (s.charAt(amp + 1) == '#') { // Decode a numeric entity
          char ch = s.charAt(amp + 2);
          try {
            if (ch == 'x' || ch == 'X') { // hex
              //         & # x A B C D ;
              //         ^ ^ ^ ^       ^
              // amp +   0 1 2 3       end - 1
              cp = Integer.parseInt(s.substring(amp + 3, end - 1), 16);
            } else { // decimal
              //         & # 1 6 0 ;
              //         ^ ^ ^     ^
              // amp +   0 1 2     end - 1
              cp = Integer.parseInt(s.substring(amp + 2, end - 1), 10);
            }
          } catch (NumberFormatException ex) {
            cp = -1; // Malformed numeric entity
          }
        } else {
          //     & q u o t ;
          //     ^           ^
          //   amp           end
          Integer cpI = HTML_ENTITY_TO_CODEPOINT.get(s.substring(amp, end));
          cp = cpI != null ? cpI.intValue() : -1;
        }
      }
      if (cp == -1) { // Don't decode
        end = amp + 1;
      } else {
        sb.append(s, pos, amp);
        sb.appendCodePoint(cp);
        pos = end;
      }
      amp = s.indexOf('&', end);
    } while (amp >= 0);
    return sb.append(s, pos, n).toString();
  }
90727
function htmlElementAsString (elem) {
  var out = []
  var className
  var classes
  var key
  var attr
  var i

  if (!elem || !elem.tagName) {
    return ''
  }

  out.push(elem.tagName.toLowerCase())
  if (elem.id) {
    out.push('#' + elem.id)
  }

  className = elem.className
  if (className && isString(className)) {
    classes = className.split(' ')
    for (i = 0; i < classes.length; i++) {
      out.push('.' + classes[i])
    }
  }
  var attrWhitelist = ['type', 'name', 'title', 'alt']
  for (i = 0; i < attrWhitelist.length; i++) {
    key = attrWhitelist[i]
    attr = elem.getAttribute(key)
    if (attr) {
      out.push('[' + key + '="' + attr + '"]')
    }
  }
  return out.join('')
}
911181
public static String htmlEncode(String input)
	{
		if (input == null)
		{
			return "";
		}
		StringBuffer retval = new StringBuffer(input);
		StringSupport.replaceAll(retval, "&", "&amp;");
		StringSupport.replaceAll(retval, "<", "&lt;");
		StringSupport.replaceAll(retval, ">", "&gt;");
		StringSupport.replaceAll(retval, "\"", "&quot;");
		return retval.toString();
	}
1329107
protected String decode(String html) throws Exception {
    String result=StringEscapeUtils.unescapeHtml4(html);
    return result;
  }
337813
function getHTMLFromResponseBody(buffer, contentType) {
  const [mimeType, ...typeOptions]  = contentType.split(/;\s*/);

  // Pick charset from content type
  if (mimeType)
    for (let typeOption of typeOptions)
      if (/^charset=/i.test(typeOption)) {
        const charset = typeOption.split('=')[1];
        return iconv.decode(buffer, charset);
      }

  // Otherwise, HTML documents only, pick charset from meta tag
  // Otherwise, HTML documents only, default charset in US is windows-1252
  const charsetInMetaTag = buffer.toString().match(MATCH_CHARSET);
  if (charsetInMetaTag)
    return iconv.decode(buffer, charsetInMetaTag[1]);
  else
    return iconv.decode(buffer, 'windows-1252');
}
1104644
function escapeStringForJavascript(content) {
  return content.replace(/(['\\])/g, '\\$1')
    .replace(/[\f]/g, "\\f")
    .replace(/[\b]/g, "\\b")
    .replace(/[\n]/g, "\\n")
    .replace(/[\t]/g, "\\t")
    .replace(/[\r]/g, "\\r")
    .replace(/[\u2028]/g, "\\u2028")
    .replace(/[\u2029]/g, "\\u2029");
}
200841
def html_encode(path):
    
    if sys.version_info > (3, 2, 0):
        return urllib.parse.quote(utils.ensure_string(path))
    else:
        return urllib.quote(utils.ensure_string(path))
1021122
def get_html(self,
                 url,
                 params=None,
                 cache_cb=None,
                 decoder_encoding=None,
                 decoder_errors=url_specified_decoder.ErrorsHandle.strict,
                 **kwargs):
        
        response = self.get(
            url=url,
            params=params,
            cache_cb=cache_cb,
            **kwargs
        )
        return url_specified_decoder.decode(
            binary=response.content,
            url=response.url,
            encoding=decoder_encoding,
            errors=decoder_errors,
        )
1293782
def textFromHTML(html):
    
    cleaner = lxml.html.clean.Cleaner(scripts=True)
    cleaned = cleaner.clean_html(html)
    return lxml.html.fromstring(cleaned).text_content()
97737
def html_with_encoding(self, url, timeout=None, encoding="utf-8"):
        
        response = self.get_response(url, timeout=timeout)
        if response:
            return self.decoder.decode(response.content, encoding)[0]
        else:
            return None
1362579
def html_to_rst(html):
    
    doc = ReSTDocument()
    doc.include_doc_string(html)
    raw_doc = doc.getvalue()
    return raw_doc.decode('utf-8')
313619
def render_html_attributes(**kwargs):
    """"""
    attr = list()
    if kwargs:
        attr = ['{}="{}"'.format(key, val) for key, val in kwargs.items()]
    return " ".join(attr).replace("css_class", "class")
291175
def html_encode(text):
    
    text = text.replace('&', '&amp;')
    text = text.replace('<', '&lt;')
    text = text.replace('>', '&gt;')
    text = text.replace('"', '&quot;')
    return text
767556
function(html) {
       return html.toString()
         .replace(/&/gmi, '&amp;')
         .replace(/"/gmi, '&quot;')
         .replace(/>/gmi, '&gt;')
         .replace(/</gmi, '&lt;')
     }