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

Breadcrumb

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

function OutputRules::attrs

1 call to OutputRules::attrs()
OutputRules::openTag in vendor/masterminds/html5/src/HTML5/Serializer/OutputRules.php
Write the opening tag.

File

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

Class

OutputRules
Generate the output html5 based on element rules.

Namespace

Masterminds\HTML5\Serializer

Code

protected function attrs($ele) {
    // FIXME: Needs support for xml, xmlns, xlink, and namespaced elements.
    if (!$ele->hasAttributes()) {
        return $this;
    }
    // TODO: Currently, this always writes name="value", and does not do
    // value-less attributes.
    $map = $ele->attributes;
    $len = $map->length;
    for ($i = 0; $i < $len; ++$i) {
        $node = $map->item($i);
        $val = $this->enc($node->value, true);
        // XXX: The spec says that we need to ensure that anything in
        // the XML, XMLNS, or XLink NS's should use the canonical
        // prefix. It seems that DOM does this for us already, but there
        // may be exceptions.
        $name = $node->nodeName;
        // Special handling for attributes in SVG and MathML.
        // Using if/elseif instead of switch because it's faster in PHP.
        if ($this->outputMode == static::IM_IN_SVG) {
            $name = Elements::normalizeSvgAttribute($name);
        }
        elseif ($this->outputMode == static::IM_IN_MATHML) {
            $name = Elements::normalizeMathMlAttribute($name);
        }
        $this->wr(' ')
            ->wr($name);
        if (isset($val) && '' !== $val || $this->nonBooleanAttribute($node)) {
            $this->wr('="')
                ->wr($val)
                ->wr('"');
        }
    }
}

API Navigation

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