PrettyMin.php
protected function removeWhitespace() {
        // Retrieve all text nodes using XPath
        $x = new \DOMXPath($this->doc);
        $nodeList = $x->query("//text()");
        foreach($nodeList as $node) {
            /** @var \DOMNode $node */

            if (in_array($node->parentNode->nodeName, $this->options['keep_whitespace_in'])) {
                continue;
            };

            $node->nodeValue = str_replace(["\r", "\n", "\t"], ' ', $node->nodeValue);
            //$node->nodeValue = preg_replace('/ {2,}/', ' ', $node->nodeValue);
            while (strpos($node->nodeValue, '  ') !== false) {
                $node->nodeValue = str_replace('  ', ' ', $node->nodeValue);
            }

            if (!in_array($node->parentNode->nodeName, $this->options['keep_whitespace_around'])) {
                if (!($node->previousSibling && in_array($node->previousSibling->nodeName,
                        $this->options['keep_whitespace_around']))
                ) {
                    $node->nodeValue = ltrim($node->nodeValue);
                }

                if (!($node->nextSibling && in_array($node->nextSibling->nodeName,
                        $this->options['keep_whitespace_around']))
                ) {
                    $node->nodeValue = rtrim($node->nodeValue);
                }
            }

            if((strlen($node->nodeValue) == 0)) {
                $node->parentNode->removeChild($node);
            }
        }
    }
protected function removeWhitespace() {
        // Retrieve all text nodes using XPath
        $x = new \DOMXPath($this->doc);
        $nodeList = $x->query("//text()");
        foreach($nodeList as $node) {
            /** @var \DOMNode $node */

            if (in_array($node->parentNode->nodeName, $this->options['keep_whitespace_in'])) {
                continue;
            };

            $node->nodeValue = str_replace(["\r", "\n", "\t"], ' ', $node->nodeValue);
            //$node->nodeValue = preg_replace('/ {2,}/', ' ', $node->nodeValue);
            while (strpos($node->nodeValue, '  ') !== false) {
                $node->nodeValue = str_replace('  ', ' ', $node->nodeValue);
            }

            if (!in_array($node->parentNode->nodeName, $this->options['keep_whitespace_around'])) {
                if (!($node->previousSibling && in_array($node->previousSibling->nodeName,
                        $this->options['keep_whitespace_around']))
                ) {
                    $node->nodeValue = ltrim($node->nodeValue);
                }

                if (!($node->nextSibling && in_array($node->nextSibling->nodeName,
                        $this->options['keep_whitespace_around']))
                ) {
                    $node->nodeValue = rtrim($node->nodeValue);
                }
            }

            if((strlen($node->nodeValue) == 0)) {
                $node->parentNode->removeChild($node);
            }
        }
    }
originally based on http://stackoverflow.com/a/18260955