Remove HTML tags, entities and superfluous characters from
    meta blocks.
196318
def metablock(parsed):
    
    parsed = " ".join(parsed.replace("\n", "").split()).replace(" ,", ",")
    return escape(strip_tags(decode_entities(parsed)))
44545
function (str) {
            return _(str).chain()
                .unescapeHTML()
                .stripTags()
                .clean()
                .value()
                .replace( matchJunk, '' )
                .toLowerCase();
        }
174627
def _remove_pre_formatting(self):
        
        preformatted_wrappers = [
            'pre',
            'code'
        ]

        for wrapper in preformatted_wrappers:
            for formatter in FORMATTERS:
                tag = FORMATTERS[formatter]
                character = formatter

                regex = r'(<{w}>.*)<{t}>(.*)</{t}>(.*</{w}>)'.format(
                    t=tag,
                    w=wrapper
                )
                repl = r'\g<1>{c}\g<2>{c}\g<3>'.format(c=character)
                self.cleaned_html = re.sub(regex, repl, self.cleaned_html)
257113
private static void cleanHeaders(Element e) {
        for (int headerIndex = 1; headerIndex < 7; headerIndex++) {
            Elements headers = getElementsByTag(e, "h" + headerIndex);
            for (Element header : headers) {
                if (getClassWeight(header) < 0
                        || getLinkDensity(header) > 0.33f) {
                    header.remove();
                }
            }
        }
    }
522744
public function cleanDocumentHead()
    {
        remove_action('wp_head', 'feed_links_extra');
        remove_action('wp_head', 'feed_links');
        remove_action('wp_head', 'rsd_link');
        remove_action('wp_head', 'wlwmanifest_link');
        remove_action('wp_head', 'index_rel_link');
        remove_action('wp_head', 'parent_post_rel_link', 10);
        remove_action('wp_head', 'start_post_rel_link', 10);
        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
        remove_action('wp_head', 'wp_generator');
    }
22033
function stripTemplate(content) {
  content = content.trim();
  if (!content) {
    return content;
  }
  return content.replace(/<(script|style)[\s\S]+<\/\1>/g, '').trim();
}
65847
def remove_doi_paragraph(tags):
    "'"
    p_tags = list(filter(lambda tag: not starts_with_doi(tag), tags))
    p_tags = list(filter(lambda tag: not paragraph_is_only_doi(tag), p_tags))
    return p_tags
978118
def cleanString(someText):
    
    ret = ''
    if someText is not None:
        ret = filter(unicode.isalnum, someText.lower())
    return ret
58528
def clean_dataset_tags(self):
        # type: () -> Tuple[bool, bool]
        
        tags_dict, wildcard_tags = Tags.tagscleanupdicts()

        def delete_tag(tag):
            logger.info('%s - Deleting tag %s!' % (self.data['name'], tag))
            return self.remove_tag(tag), False

        def update_tag(tag, final_tags, wording, remove_existing=True):
            text = '%s - %s: %s -> ' % (self.data['name'], wording, tag)
            if not final_tags:
                logger.error('%snothing!' % text)
                return False, True
            tags_lower_five = final_tags[:5].lower()
            if tags_lower_five == 'merge' or tags_lower_five == 'split' or (
                    ';' not in final_tags and len(final_tags) > 50):
                logger.error('%s%s - Invalid final tag!' % (text, final_tags))
                return False, True
            if remove_existing:
                self.remove_tag(tag)
            tags = ', '.join(self.get_tags())
            if self.add_tags(final_tags.split(';')):
                logger.info('%s%s! Dataset tags: %s' % (text, final_tags, tags))
            else:
                logger.warning(
                    '%s%s - At least one of the tags already exists! Dataset tags: %s' % (text, final_tags, tags))
            return True, False

        def do_action(tag, tags_dict_key):
            whattodo = tags_dict[tags_dict_key]
            action = whattodo[u'action']
            final_tags = whattodo[u'final tags (semicolon separated)']
            if action == u'Delete':
                changed, error = delete_tag(tag)
            elif action == u'Merge':
                changed, error = update_tag(tag, final_tags, 'Merging')
            elif action == u'Fix spelling':
                changed, error = update_tag(tag, final_tags, 'Fixing spelling')
            elif action == u'Non English':
                changed, error = update_tag(tag, final_tags, 'Anglicising', remove_existing=False)
            else:
                changed = False
                error = False
            return changed, error

        def process_tag(tag):
            changed = False
            error = False
            if tag in tags_dict.keys():
                changed, error = do_action(tag, tag)
            else:
                for wildcard_tag in wildcard_tags:
                    if fnmatch.fnmatch(tag, wildcard_tag):
                        changed, error = do_action(tag, wildcard_tag)
                        break
            return changed, error

        anychange = False
        anyerror = False
        for tag in self.get_tags():
            changed, error = process_tag(tag)
            if changed:
                anychange = True
            if error:
                anyerror = True

        return anychange, anyerror
131650
def strip_tags(self, content, smart=False):
        
        from lxml.html import fromstring

        return get_node_text(fromstring(content), smart=smart)
125962
def unescape_html(text):
    
    def fixup(m):
        text = m.group(0)
        if text[:2] == "&#":
            # character reference
            try:
                if text[:3] == "&#x":
                    return unicode_char(int(text[3:-1], 16))
                else:
                    return unicode_char(int(text[2:-1]))
            except ValueError:
                pass
        else:
            # named entity
            try:
                text = unicode_char(htmlentities.name2codepoint[text[1:-1]])
            except KeyError:
                pass
        return text  # leave as is
    return re.sub(r"&#?\w+;", fixup, text)
422775
def strip(self, text):
        ''''''
        tags, results = [], []
        return self.re_tag.sub(lambda m: self.clear_tag(m, tags, results), text)
282164
def fix_django_headers(meta):
	
	ret = {}
	for k, v in meta.items():
		if k.startswith("HTTP_"):
			k = k[len("HTTP_") :]
		elif k not in ("CONTENT_LENGTH", "CONTENT_TYPE"):
			# Skip CGI garbage
			continue

		ret[k.lower().replace("_", "-")] = v

	return ret
408519
function sanitizeHtml(html, whitelist) {
        return html.replace(/<[^>]*>?/gi, function(tag) {
            return tag.match(whitelist) ? tag : '';
        });
    }
453301
function cleanUpData(){
      var v = $contentDomNode.html().replace(/<br\s*\/?>/mg,"\n");
      v = v.replace(/<div>/gi,"\n").replace(/<\/div>/gi,'');
      v = v.replace(/(<([^>]+)>)/ig,'');
      return $.trim(v.replace(/&nbsp;/ig,''));
    }
141174
def remove_tag_all(self, resource_type, resource_id, **_params):
        """"""
        return self.delete(self.tags_path % (resource_type, resource_id))
366139
def strip_html_comments(text):
    """"""
    lines = text.splitlines(True)  # preserve line endings.

    # Remove HTML comments (which we only allow to take a special form).
    new_lines = filter(lambda line: not line.startswith("<!--"), lines)

    return "".join(new_lines)