League\HTMLToMarkdown\HtmlConverter::convertChildren PHP Method

convertChildren() private method

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.
private convertChildren ( League\HTMLToMarkdown\ElementInterface $element )
$element League\HTMLToMarkdown\ElementInterface
    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);
    }