コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function matches(Element $element)
 {
     if (!in_array($element->getTagName(), $this->tags)) {
         return false;
     }
     $this->element = $element;
     return $this;
 }
コード例 #2
0
 /**
  * Determine paragraph type
  *
  * @param  \Candybanana\HtmlToCarbonJson\Element|null
  * @return string
  */
 protected function paragraphType(Element $element)
 {
     switch ($element->getTagName()) {
         case 'h2':
             return $this->config['minimumHeading'] == 'h1' ? 'h1' : 'h2';
         case 'h3':
         case 'h4':
         case 'h5':
         case 'h6':
             if ($this->config['minimumHeading'] !== 'h3') {
                 return $this->config['minimumHeading'];
             }
             return 'h3';
         case 'code':
             return 'blockquote';
             // fine as it is!
         // fine as it is!
         default:
             return $element->getTagName();
     }
 }
コード例 #3
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;
 }