コード例 #1
0
 /**
  * Extract the equivalent of 'Sections' in Carbon from the document
  *
  * @param  \Candybanana\HtmlToCarbonJson\Element
  * @return boolean
  */
 protected function extractSections(Element $element)
 {
     // recursively iterate until we get to the innermost child
     if ($element->hasChildren()) {
         foreach ($element->getChildren() as $child) {
             // we've found our section, return
             if ($this->extractSections($child)) {
                 return;
             }
         }
     }
     // is this a block element with children?
     // 30/10/16: hacky fix here for LIs containing children. @todo: Proper fix = custom isBlock() function.
     if ($element->getTagName() !== 'li' && $element->isBlock() && $element->hasChildren()) {
         // does it have a parent? If so that's our section
         if ($parent = $element->getParent()) {
             $this->sectionsHtml[] = $parent;
             // remove it from the DOM
             // @todo: check if this is the root element - if so error out
             $parent->remove();
             return true;
         }
     }
     // we're done with this node
     return false;
 }