removes whitespace-only text node children
548034
function(element) {
    element = $(element);
    var node = element.firstChild;
    while (node) {
      var nextNode = node.nextSibling;
      if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
        element.removeChild(node);
      node = nextNode;
    }
    return element;
  }
739978
public function clear()
    {
        if ($this->childNodes->length > 0) {
            foreach ($this->childNodes as $childNode) {
                $this->removeChild($childNode);
            }
        }

        $this->textContent = null;
    }
1282685
private void cleanContentLeadingSpaces()
    {
        if (getContent().length() > 0) {
            if (fPreviousInlineText.length() == 0
                || fPreviousInlineText
                .charAt(fPreviousInlineText.length() - 1) == ' ')
            {
                trimLeadingWhiteSpaces();
            }
        }
    }
1355997
function elementTrailingWhitespace(el) {
  let style = getComputedStyle(el, null)
  let display = style.getPropertyValue('display')

  let lastNotIgnoredChild = () => {
    for(let i = el.children.length - 1; i >= 0; i--) {
      let n = el.children[i]
      if(!ignoredNode(n)) return n
    }
    return null
  }

  if(display === 'inline') {
    let last = lastNotIgnoredChild()
    if(last && last.nodeType === Node.ELEMENT_NODE) {
      let lastChunks = []
      innerRichText(last, lastChunks)
      return elementTrailingWhitespace(last, lastChunks)
    } else {
      return ''
    }
  } else if(display === 'inline-block'
    || display === 'inline-table'
    || display === 'none'
    || display === 'table-column'
    || display === 'table-column-group') {
    return ''
  } else if(display === 'table-cell') {
    return '\t'
  } else {
    let elChunks = []
    innerRichText(el, elChunks)
    if(elChunks && elChunks.length > 0) {
      let marginBottom = getPixelStyleProperty(style, 'margin-bottom')
      let fontSize = getPixelStyleProperty(style, 'font-size')
      if(marginBottom >= fontSize / 2) return '\n\n'
      else return '\n'
    } else return ''
  }
}
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;
  }
687868
private String  textXMLSpaceTransform(String text, boolean isFirstChild, boolean isLastChild)
   {
      if (state.spacePreserve)  // xml:space = "preserve"
         return text.replaceAll("[\\n\\t]", " ");

      // xml:space = "default"
      text = text.replaceAll("\\n", "");
      text = text.replaceAll("\\t", " ");
      //text = text.trim();
      if (isFirstChild)
         text = text.replaceAll("^\\s+",  "");
      if (isLastChild)
         text = text.replaceAll("\\s+$",  "");
      return text.replaceAll("\\s{2,}", " ");
   }
750543
def cleanup_nodes(doc):
    
    for node in doc.documentElement.childNodes:
        if node.nodeType == Node.TEXT_NODE and node.nodeValue.isspace():
            doc.documentElement.removeChild(node)
    return doc
630334
def _get_stripped_text_from_node(self, node):
        """"""
        return (
            node.text_content()
            .replace(u"\u00A0", " ")
            .replace("\t", "")
            .replace("\n", "")
            .strip()
        )
120057
function( text ){
			if(text && text.length){
				var i = text.length,
					x = 0;

				// turn all whitespace chars at end into spaces
				while (i--) {
					if(this.isOnlyWhiteSpace(text[i])){
						text = this.replaceCharAt( text, i, ' ' );
					}else{
						break;
					}
				}

				// turn all whitespace chars at start into spaces
				i = text.length;
				while (x < i) {
					if(this.isOnlyWhiteSpace(text[x])){
						text = this.replaceCharAt( text, i, ' ' );
					}else{
						break;
					}
					x++;
				}
			}
			return this.trim(text);
		}
131650
def strip_tags(self, content, smart=False):
        
        from lxml.html import fromstring

        return get_node_text(fromstring(content), smart=smart)
1629
function _cleanNodes (nodes) {
  nodes.forEach(function (tag) {
    // avoiding circular structure
    delete tag._parent;

    // removing temporary tester
    delete tag.match_closer;

    // cleaning empty attributes
    if( tag.attrs && Object.keys(tag.attrs).length === 0 ) delete tag.attrs;

    // cleaning empty children
    if( tag._ instanceof Array ) {
      if( !tag._.length ) delete tag._;
      else _cleanNodes(tag._);
    }

  });
  return nodes;
}
705447
function removeWhitespace(node) {
  node.value = node.value.filter(node => !isWhitespace(node))
}
971234
static void removeWhitespace(Node node)
    {
        NodeList childList = node.getChildNodes();
        List<Node> toRemove = new ArrayList<Node>();
        for (int i = 0; i < childList.getLength(); i++)
        {
            Node child = childList.item(i);
            if (child.getNodeType() == Node.TEXT_NODE)
            {
                String text = child.getTextContent();
                String trimmed = text.trim();
                if (trimmed.isEmpty())
                {
                    toRemove.add(child);
                }
                else if (trimmed.length() < text.length())
                {
                    child.setTextContent(trimmed);
                }
            }
            removeWhitespace(child);
        }
        for (Node c : toRemove)
        {
            node.removeChild(c);
        }
    }
1001650
def _strip(text):
        """"""
        text = text.strip()
        text = text.replace('  ', ' ')  # remove duplicate spaces
        text = text.lower()
        for joiner in TextTitle.JOINERS:
            text = text.replace(joiner, 'and')
        for article in TextTitle.ARTICLES:
            if text.startswith(article + ' '):
                text = text[len(article) + 1:]
                break
        return text
318858
private function removeWhitespaceAroundTags(SimpleHtmlDom $element)
    {
        if (isset(self::$trimWhitespaceFromTags[$element->tag])) {
            $node = $element->getNode();

            /** @var \DOMNode[] $candidates */
            $candidates = [];
            if ($node->childNodes->length > 0) {
                $candidates[] = $node->firstChild;
                $candidates[] = $node->lastChild;
                $candidates[] = $node->previousSibling;
                $candidates[] = $node->nextSibling;
            }

            foreach ($candidates as &$candidate) {
                if ($candidate === null) {
                    continue;
                }

                if ($candidate->nodeType === \XML_TEXT_NODE) {
                    $candidate->nodeValue = \preg_replace(self::$regExSpace, ' ', $candidate->nodeValue);
                }
            }
        }
    }
1043510
function( node ) {
			var out = '',
				j = 0;

			if(node.tagName && this.excludeTags.indexOf( node.tagName.toLowerCase() ) > -1){
				return out;
			}

			// if node is a text node get its text
			if(node.nodeType && node.nodeType === 3){
				out += modules.domUtils.getElementText( node );
			}

			// get the text of the child nodes
			if(node.childNodes && node.childNodes.length > 0){
				for (j = 0; j < node.childNodes.length; j++) {
					var text = this.walkTreeForText( node.childNodes[j] );
					if(text !== undefined){
						out += text;
					}
				}
			}

			// if it's a block level tag add an additional space at the end
			if(node.tagName && this.blockLevelTags.indexOf( node.tagName.toLowerCase() ) !== -1){
				out += ' ';
			}

			return (out === '')? undefined : out ;
		}
796430
def fix_whitespace(tokens, start, result):
    """"""
    for e in result:
        for child in e.iter():
            child.text = child.text.replace(' , ', ', ')
            for hyphen in HYPHENS:
                child.text = child.text.replace(' %s ' % hyphen, '%s' % hyphen)
            child.text = re.sub(r'- (.) -', r'-\1-', child.text)
    return result