Goetas\Twital\Attribute\IfAttribute::removeWhitespace PHP Method

removeWhitespace() public static method

public static removeWhitespace ( DOMElement $element )
$element DOMElement
    public static function removeWhitespace(\DOMElement $element)
    {
        while ($el = $element->nextSibling) {
            if ($el instanceof \DOMText) {
                $element->parentNode->removeChild($el);
            } else {
                break;
            }
        }
    }

Usage Example

Beispiel #1
0
 public function visit(\DOMAttr $att, Compiler $context)
 {
     $node = $att->ownerElement;
     if (!($prev = IfAttribute::findPrevElement($node))) {
         throw new Exception("The attribute 'elseif' must be the very next sibling of an 'if' of 'elseif' attribute");
     }
     $pi = $context->createControlNode("elseif " . html_entity_decode($att->value));
     $node->parentNode->insertBefore($pi, $node);
     if (!($nextElement = IfAttribute::findNextElement($node)) || !$nextElement->hasAttributeNS(Twital::NS, 'elseif') && !$nextElement->hasAttributeNS(Twital::NS, 'else')) {
         $pi = $context->createControlNode("endif");
         $node->parentNode->insertBefore($pi, $node->nextSibling);
         // insert after
     } else {
         IfAttribute::removeWhitespace($node);
     }
     $node->removeAttributeNode($att);
 }