public function toDOMElement()

in src/Facebook/InstantArticles/Elements/InstantArticle.php [495:580]


    public function toDOMElement($document = null)
    {
        if (!$document) {
            $document = new \DOMDocument();
        }

        // Builds and appends head to the HTML document
        $html = $document->createElement('html');
        if ($this->isRTLEnabled) {
            $html->setAttribute('dir', 'rtl');
        }
        $head = $document->createElement('head');
        $html->appendChild($head);

        $link = $document->createElement('link');
        $link->setAttribute('rel', 'canonical');
        $link->setAttribute('href', $this->canonicalURL);
        $head->appendChild($link);

        $charset = $document->createElement('meta');
        $charset->setAttribute('charset', $this->charset);
        $head->appendChild($charset);

        $this->addMetaProperty('op:markup_version', $this->markupVersion);
        if ($this->header && count($this->header->getAds()) > 0) {
            if ($this->isAutomaticAdPlaced) {
                $this->addMetaProperty(
                    'fb:use_automatic_ad_placement',
                    'enable=true ad_density=' . $this->adDensity
                );
            } else {
                $this->addMetaProperty('fb:use_automatic_ad_placement', 'false');
            }
        }

        if ($this->header && $this->isRecirculationAdPlaced && $this->adRecirculationPlacement) {
            $this->addMetaProperty(
                'fb:op-recirculation-ads',
                $this->adRecirculationPlacement
            );
        }

        if ($this->style) {
            $this->addMetaProperty('fb:article_style', $this->style);
        }

        // Adds all meta properties
        foreach ($this->metaProperties as $property_name => $property_content) {
            $head->appendChild(
                $this->createMetaElement(
                    $document,
                    $property_name,
                    $property_content
                )
            );
        }

        // Build and append body and article tags to the HTML document
        $body = $document->createElement('body');
        $article = $document->createElement('article');
        $body->appendChild($article);
        $html->appendChild($body);
        Element::appendChild($article, $this->header, $document);
        if ($this->children) {
            foreach ($this->children as $child) {
                if (Type::is($child, TextContainer::getClassName())) {
                    if (count($child->getTextChildren()) === 0) {
                        continue;
                    }

                    if (count($child->getTextChildren()) === 1) {
                        if (Type::is($child->getTextChildren()[0], Type::STRING) &&
                            trim($child->getTextChildren()[0]) === '') {
                            continue;
                        }
                    }
                }
                Element::appendChild($article, $child, $document);
            }
            Element::appendChild($article, $this->footer, $document);
        } else {
            $article->appendChild($document->createTextNode(''));
        }

        return $html;
    }