Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. OutputRules.php

function OutputRules::element

Overrides RulesInterface::element

File

vendor/masterminds/html5/src/HTML5/Serializer/OutputRules.php, line 209

Class

OutputRules
Generate the output html5 based on element rules.

Namespace

Masterminds\HTML5\Serializer

Code

public function element($ele) {
    $name = $ele->tagName;
    // Per spec:
    // If the element has a declared namespace in the HTML, MathML or
    // SVG namespaces, we use the lname instead of the tagName.
    if ($this->traverser
        ->isLocalElement($ele)) {
        $name = $ele->localName;
    }
    // If we are in SVG or MathML there is special handling.
    // Using if/elseif instead of switch because it's faster in PHP.
    if ('svg' == $name) {
        $this->outputMode = static::IM_IN_SVG;
        $name = Elements::normalizeSvgElement($name);
    }
    elseif ('math' == $name) {
        $this->outputMode = static::IM_IN_MATHML;
    }
    $this->openTag($ele);
    if (Elements::isA($name, Elements::TEXT_RAW)) {
        foreach ($ele->childNodes as $child) {
            if ($child instanceof \DOMCharacterData) {
                $this->wr($child->data);
            }
            elseif ($child instanceof \DOMElement) {
                $this->element($child);
            }
        }
    }
    else {
        // Handle children.
        if ($ele->hasChildNodes()) {
            $this->traverser
                ->children($ele->childNodes);
        }
        // Close out the SVG or MathML special handling.
        if ('svg' == $name || 'math' == $name) {
            $this->outputMode = static::IM_IN_HTML;
        }
    }
    // If not unary, add a closing tag.
    if (!Elements::isA($name, Elements::VOID_TAG)) {
        $this->closeTag($ele);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal