Removes the wrapping that might have resulted when using get_html_tree().
489865
def strip_wrapping(html):
    
    if html.startswith('<div>') and html.endswith('</div>'):
        html = html[5:-6]
    return html.strip()
1104398
def word_wrap_tree(parented_tree, width=0):
    """"""
    if width != 0:
        for i, leaf_text in enumerate(parented_tree.leaves()):
            dedented_text = textwrap.dedent(leaf_text).strip()
            parented_tree[parented_tree.leaf_treeposition(i)] = textwrap.fill(dedented_text, width=width)
    return parented_tree
767558
def remove_nesting(dom, tag_name):
    
    for node in dom.getElementsByTagName(tag_name):
        for ancestor in ancestors(node):
            if ancestor is node:
                continue
            if ancestor is dom.documentElement:
                break
            if ancestor.tagName == tag_name:
                unwrap(node)
                break
1270904
def clean_html(self, html):
        """"""
        result_type = type(html)
        if isinstance(html, six.string_types):
            doc = html_fromstring(html)
        else:
            doc = copy.deepcopy(html)
        self(doc)
        if issubclass(result_type, six.binary_type):
            return tostring(doc, encoding='utf-8')
        elif issubclass(result_type, six.text_type):
            return tostring(doc, encoding='unicode')
        else:
            return doc
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)
693084
def remove_whitespace(self, html):
        
        # Does python have a better way to do exactly this?
        clean_html = html
        for char in ("\r", "\n", "\t"):
            clean_html = clean_html.replace(char, "")
        return clean_html
345031
def trim(self):
        
        # Only allow leaves to stay on list (highest-resolution) level
        return

        for l in self._levels[-2::-1]:
            for n in l:
                if n.is_leaf:
                    n.parent.remove_child(n.label)

        self._clear_all_leaves()
909243
function cleanTree ( node, preserveWS ) {
    var children = node.childNodes,
        nonInlineParent, i, l, child, nodeName, nodeType, rewriter, childLength,
        startsWithWS, endsWithWS, data, sibling;

    nonInlineParent = node;
    while ( isInline( nonInlineParent ) ) {
      nonInlineParent = nonInlineParent.parentNode;
    }
    walker.root = nonInlineParent;

    for ( i = 0, l = children.length; i < l; i += 1 ) {
      child = children[i];
      nodeName = child.nodeName;
      nodeType = child.nodeType;
      rewriter = stylesRewriters[ nodeName ];
      if ( nodeType === ELEMENT_NODE ) {
        childLength = child.childNodes.length;
        if ( rewriter ) {
          child = rewriter( child, node );
        } else if ( blacklist.test( nodeName ) ) {
          node.removeChild( child );
          i -= 1;
          l -= 1;
          continue;
        } else if ( !allowedBlock.test( nodeName ) && !isInline( child ) ) {
          i -= 1;
          l += childLength - 1;
          node.replaceChild( empty( child ), child );
          continue;
        }
        if ( childLength ) {
          cleanTree( child, preserveWS || ( nodeName === 'PRE' ) );
        }
      } else {
        if ( nodeType === TEXT_NODE ) {
          data = child.data;
          startsWithWS = !notWS.test( data.charAt( 0 ) );
          endsWithWS = !notWS.test( data.charAt( data.length - 1 ) );
          if ( preserveWS || ( !startsWithWS && !endsWithWS ) ) {
            continue;
          }
          // Iterate through the nodes; if we hit some other content
          // before the start of a new block we don't trim
          if ( startsWithWS ) {
            walker.currentNode = child;
            while ( sibling = walker.previousPONode() ) {
              nodeName = sibling.nodeName;
              if ( nodeName === 'IMG' ||
                   ( nodeName === '#text' &&
                     notWS.test( sibling.data ) ) ) {
                break;
              }
              if ( !isInline( sibling ) ) {
                sibling = null;
                break;
              }
            }
            data = data.replace( /^[ \t\r\n]+/g, sibling ? ' ' : '' );
          }
          if ( endsWithWS ) {
            walker.currentNode = child;
            while ( sibling = walker.nextNode() ) {
              if ( nodeName === 'IMG' ||
                   ( nodeName === '#text' &&
                     notWS.test( sibling.data ) ) ) {
                break;
              }
              if ( !isInline( sibling ) ) {
                sibling = null;
                break;
              }
            }
            data = data.replace( /[ \t\r\n]+$/g, sibling ? ' ' : '' );
          }
          if ( data ) {
            child.data = data;
            continue;
          }
        }
        node.removeChild( child );
        i -= 1;
        l -= 1;
      }
    }
    return node;
  }
730890
function () {
            var wrapper = this,
              element = wrapper.element || {},
              shadows = wrapper.shadows,
              parentToClean = wrapper.renderer.isSVG && element.nodeName === 'SPAN' && wrapper.parentGroup,
              grandParent,
              key,
              i;

            // remove events
            element.onclick = element.onmouseout = element.onmouseover = element.onmousemove = element.point = null;
            stop(wrapper); // stop running animations

            if (wrapper.clipPath) {
                wrapper.clipPath = wrapper.clipPath.destroy();
            }

            // Destroy stops in case this is a gradient object
            if (wrapper.stops) {
                for (i = 0; i < wrapper.stops.length; i++) {
                    wrapper.stops[i] = wrapper.stops[i].destroy();
                }
                wrapper.stops = null;
            }

            // remove element
            wrapper.safeRemoveChild(element);

            // destroy shadows
            if (shadows) {
                each(shadows, function (shadow) {
                    wrapper.safeRemoveChild(shadow);
                });
            }

            // In case of useHTML, clean up empty containers emulating SVG groups (#1960, #2393, #2697).
            while (parentToClean && parentToClean.div && parentToClean.div.childNodes.length === 0) {
                grandParent = parentToClean.parentGroup;
                wrapper.safeRemoveChild(parentToClean.div);
                delete parentToClean.div;
                parentToClean = grandParent;
            }

            // remove from alignObjects
            if (wrapper.alignTo) {
                erase(wrapper.renderer.alignedObjects, wrapper);
            }

            for (key in wrapper) {
                delete wrapper[key];
            }

            return null;
        }
438744
function() {
    var elTable = this._elTable;
    if(elTable) {
        Ev.purgeElement(elTable, true);
        elTable.parentNode.removeChild(elTable);
        this._elCaption = null;
        this._elColgroup = null;
        this._elThead = null;
        this._elTbody = null;
    }
}
608653
def strip_html(html)
      return @stripped_html if @stripped_html
      allowed = @settings[:allowed_tags]
      reg = if allowed.any?
        Regexp.new(
          %(<(?!(\\s|\\/)*(#{
            allowed.map {|tag| Regexp.escape( tag )}.join( "|" )
          })( |>|\\/|'|"|<|\\s*\\z))[^>]*(>+|\\s*\\z)),
          Regexp::IGNORECASE | Regexp::MULTILINE, 'u'
        )
      else
        /<[^>]*(>+|\s*\z)/m
      end
       @stripped_html = html.gsub(reg,'')
    end
1070305
private static function RemoveUndefinedVars(){
            $oThis = self::CreateInstanceIfNotExists();
            $iOffset = 0;

            while(preg_match('/{\$(.*?)}/i', $oThis->sBuffer, $aMatches, PREG_OFFSET_CAPTURE, $iOffset)){
                $oThis->sBuffer = str_replace($aMatches[0][0], "false", $oThis->sBuffer);
                $iOffset = $aMatches[0][1]+strlen($aMatches[0][0]);
            }
        }
809599
def strip_HTML(s):
    """"""
    result = ''
    total = 0
    for c in s:
        if c == '<':
            total = 1
        elif c == '>':
            total = 0
            result += ' '
        elif total == 0:
            result += c
    return result
234676
def clean(self):
        
        super(CTENode, self).clean()
        if self.parent and self.pk in getattr(self.parent, self._cte_node_path):
            raise ValidationError(_("A node cannot be made a descendant of itself."))
329875
def trim_tree_before(element, include_element=True, keep_head=True):
    
    el = element
    for parent_el in element.iterancestors():
        parent_el.text = None
        if el != element or include_element:
            el = el.getprevious()
        else:
            parent_el.text = el.tail
        while el is not None:
            remove_el = el
            el = el.getprevious()
            tag = remove_el.tag
            is_head = isinstance(tag, string_class) and tag.lower() == 'head'
            if not keep_head or not is_head:
                parent_el.remove(remove_el)
        el = parent_el
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)
1341161
def _clean_html(html):
    
    content = html.replace(u'&#x000A;', u'\n').replace(u'¶', '')
    content = _LINK_PATTERN.sub(u'', content)
    content = _HTML_TAG_PATTERN.sub(u'', content)
    content = _BACKSLASH_PATTERN.sub(u'\n', content)
    return content