/**
  * Convert Children
  *
  * Recursive function to drill into the DOM and convert each node into BBCode from the inside out.
  *
  * Finds children of each node and convert those to #text nodes containing their BBCode equivalent,
  * starting with the innermost element and working up to the outermost element.
  *
  * @param ElementInterface $element
  */
 private function convertChildren(ElementInterface $element)
 {
     // Don't convert HTML code inside <code> and <pre> blocks to BBCode - that should stay as HTML
     if ($element->isDescendantOf(array('pre', 'code'))) {
         return;
     }
     // If the node has children, convert those to BBCode first
     if ($element->hasChildren()) {
         foreach ($element->getChildren() as $child) {
             $this->convertChildren($child);
         }
     }
     // Now that child nodes have been converted, convert the original node
     $bbcode = $this->convertToBBCode($element);
     // Create a DOM text node containing the BBCode equivalent of the original node
     // Replace the old $node e.g. '<h3>Title</h3>' with the new $bbcode_node e.g. '### Title'
     $element->setFinalBBCode($bbcode);
 }
 /**
  * Convert Children
  *
  * Recursive function to drill into the DOM and convert each node into Markdown from the inside out.
  *
  * Finds children of each node and convert those to #text nodes containing their Markdown equivalent,
  * starting with the innermost element and working up to the outermost element.
  *
  * @param ElementInterface $element
  */
 private function convertChildren(ElementInterface $element)
 {
     // Don't convert HTML code inside <code> and <pre> blocks to Markdown - that should stay as HTML
     // except if the current node is a code tag, which needs to be converted by the CodeConverter.
     if ($element->isDescendantOf(array('pre', 'code')) && $element->getTagName() !== 'code') {
         return;
     }
     // If the node has children, convert those to Markdown first
     if ($element->hasChildren()) {
         foreach ($element->getChildren() as $child) {
             $this->convertChildren($child);
         }
     }
     // Now that child nodes have been converted, convert the original node
     $markdown = $this->convertToMarkdown($element);
     // Create a DOM text node containing the Markdown equivalent of the original node
     // Replace the old $node e.g. '<h3>Title</h3>' with the new $markdown_node e.g. '### Title'
     $element->setFinalMarkdown($markdown);
 }