Example #1
0
 /**
  * Write a text node.
  *
  * @param \DOMText $ele
  *            The text node to write.
  */
 public function text($ele)
 {
     if (isset($ele->parentNode) && isset($ele->parentNode->tagName) && Elements::isA($ele->parentNode->localName, Elements::TEXT_RAW)) {
         $this->wr($ele->data);
         return;
     }
     // FIXME: This probably needs some flags set.
     $this->wr($this->enc($ele->data));
 }
Example #2
0
 public function endTag($name)
 {
     $lname = $this->normalizeTagName($name);
     // Ignore closing tags for unary elements.
     if (Elements::isA($name, Elements::VOID_TAG)) {
         return;
     }
     if ($this->insertMode <= static::IM_BEFORE_HTML) {
         // 8.2.5.4.2
         if (in_array($name, array('html', 'br', 'head', 'title'))) {
             $this->startTag('html');
             $this->endTag($name);
             $this->insertMode = static::IM_BEFORE_HEAD;
             return;
         }
         // Ignore the tag.
         $this->parseError("Illegal closing tag at global scope.");
         return;
     }
     // Special case handling for SVG.
     if ($this->insertMode == static::IM_IN_SVG) {
         $lname = Elements::normalizeSvgElement($lname);
     }
     // See https://github.com/facebook/hhvm/issues/2962
     if (defined('HHVM_VERSION') && ($cid = $this->current->getAttribute('html5-php-fake-id-attribute'))) {
         $this->current->removeAttribute('html5-php-fake-id-attribute');
     } else {
         $cid = spl_object_hash($this->current);
     }
     // XXX: Not sure whether we need this anymore.
     // if ($name != $lname) {
     // return $this->quirksTreeResolver($lname);
     // }
     // XXX: HTML has no parent. What do we do, though,
     // if this element appears in the wrong place?
     if ($lname == 'html') {
         return;
     }
     // remove the namespaced definded by current node
     if (isset($this->pushes[$cid])) {
         for ($i = 0; $i < $this->pushes[$cid][0]; $i++) {
             array_shift($this->nsStack);
         }
         unset($this->pushes[$cid]);
     }
     if (!$this->autoclose($lname)) {
         $this->parseError('Could not find closing tag for ' . $lname);
     }
     // switch ($this->insertMode) {
     switch ($lname) {
         case "head":
             $this->insertMode = static::IM_AFTER_HEAD;
             break;
         case "body":
             $this->insertMode = static::IM_AFTER_BODY;
             break;
         case "svg":
         case "mathml":
             $this->insertMode = static::IM_IN_BODY;
             break;
     }
 }
Example #3
0
 public function testIsA()
 {
     $this->assertTrue(Elements::isA('script', Elements::KNOWN_ELEMENT));
     $this->assertFalse(Elements::isA('scriptypoo', Elements::KNOWN_ELEMENT));
     $this->assertTrue(Elements::isA('script', Elements::TEXT_RAW));
     $this->assertFalse(Elements::isA('script', Elements::TEXT_RCDATA));
     $voidElements = array('area', 'base', 'basefont', 'bgsound', 'br', 'col', 'command', 'embed', 'frame', 'hr', 'img');
     foreach ($voidElements as $element) {
         $this->assertTrue(Elements::isA($element, Elements::VOID_TAG), 'Void element test failed on: ' . $element);
     }
     $nonVoid = array('span', 'a', 'div');
     foreach ($nonVoid as $tag) {
         $this->assertFalse(Elements::isA($tag, Elements::VOID_TAG), 'Void element test failed on: ' . $tag);
     }
     $blockTags = array('address', 'article', 'aside', 'audio', 'blockquote', 'canvas', 'dd', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table', 'tfoot', 'ul', 'video');
     foreach ($blockTags as $tag) {
         $this->assertTrue(Elements::isA($tag, Elements::BLOCK_TAG), 'Block tag test failed on: ' . $tag);
     }
     $nonBlockTags = array('span', 'img', 'label');
     foreach ($nonBlockTags as $tag) {
         $this->assertFalse(Elements::isA($tag, Elements::BLOCK_TAG), 'Block tag test failed on: ' . $tag);
     }
 }