private function applyAttributes(AbstractBlock $block)
 {
     $previous = null;
     $prepend = null;
     foreach ($block->getChildren() as $key => $child) {
         if ($child instanceof Attributes) {
             if ($child->isPrepend()) {
                 $prepend = $child;
             } elseif ($child->isAppend()) {
                 $previous->data['attributes'] = AttributesUtils::merge($previous ?: $block, $child->getAttributes());
             }
             $block->removeChild($child);
         } else {
             if (isset($prepend)) {
                 $child->data['attributes'] = AttributesUtils::merge($child, $prepend->getAttributes());
             }
             $prepend = null;
             $this->applyAttributes($child);
             $previous = $child;
         }
     }
     if (isset($prepend)) {
         $block->data['attributes'] = AttributesUtils::merge($block, $prepend->getAttributes());
     }
     return $block;
 }