public function toDOMElement()

in src/Facebook/InstantArticles/Elements/Caption.php [359:401]


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

        $element = $document->createElement('figcaption');

        // title markup REQUIRED
        if ($this->title && (!$this->subTitle && !$this->credit)) {
            $element->appendChild($this->title->textToDOMDocumentFragment($document));
        } else {
            Element::appendChild($element, $this->title, $document);
        }

        // subtitle markup optional
        Element::appendChild($element, $this->subTitle, $document);

        $element->appendChild($this->textToDOMDocumentFragment($document));

        // credit markup optional
        Element::appendChild($element, $this->credit, $document);

        // Formating markup
        if ($this->textAlignment || $this->verticalAlignment || $this->fontSize || $this->position) {
            $classes = [];
            if ($this->textAlignment) {
                $classes[] = $this->textAlignment;
            }
            if ($this->verticalAlignment) {
                $classes[] = $this->verticalAlignment;
            }
            if ($this->fontSize) {
                $classes[] = $this->fontSize;
            }
            if ($this->position) {
                $classes[] = $this->position;
            }
            $element->setAttribute('class', implode(' ', $classes));
        }

        return $element;
    }