From 56d9b965f6d81f540a75786fae3800fc513985d6 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Mon, 29 Apr 2013 15:45:40 -0500 Subject: Moved the traverser unary tests to the elements class. --- src/HTML5/Elements.php | 7 ++++--- src/HTML5/Serializer/Traverser.php | 39 +++----------------------------------- 2 files changed, 7 insertions(+), 39 deletions(-) (limited to 'src/HTML5') diff --git a/src/HTML5/Elements.php b/src/HTML5/Elements.php index afa3327..429dbbf 100644 --- a/src/HTML5/Elements.php +++ b/src/HTML5/Elements.php @@ -35,12 +35,12 @@ class Elements { "a" => 1, "abbr" => 1, "address" => 25, // NORMAL | UNARY_TAG | AUTOCLOSE_P - "area" => 1, + "area" => 9, // NORMAL | UNARY_TAG "article" => 17, // NORMAL | AUTOCLOSE_P "aside" => 17, // NORMAL | AUTOCLOSE_P, "audio" => 1, "b" => 1, - "base" => 9, // | UNARY_TAG + "base" => 9, // NORMAL | UNARY_TAG "bdi" => 1, "bdo" => 1, "blockquote" => 17, // NORMAL | AUTOCLOSE_P, @@ -51,7 +51,7 @@ class Elements { "caption" => 1, "cite" => 1, "code" => 1, - "col" => 1, + "col" => 9, // NORMAL | UNARY_TAG "colgroup" => 1, "command" => 9, // NORMAL | UNARY_TAG //"data" => 1, // This is highly experimental and only part of the whatwg spec (not w3c). See https://developer.mozilla.org/en-US/docs/HTML/Element/data @@ -147,6 +147,7 @@ class Elements { 'basefont' => 8, // UNARY_TAG 'bgsound' => 8, // UNARY_TAG 'noframes' => 2, // RAW_TEXT + 'frame' => 9, // NORMAL | UNARY_TAG 'center' => 16, 'dir' => 16, 'listing' => 16, // AUTOCLOSE_P 'plaintext' => 48, // AUTOCLOSE_P | TEXT_PLAINTEXT 'applet' => 0, diff --git a/src/HTML5/Serializer/Traverser.php b/src/HTML5/Serializer/Traverser.php index 735e413..cdbd64a 100644 --- a/src/HTML5/Serializer/Traverser.php +++ b/src/HTML5/Serializer/Traverser.php @@ -1,6 +1,8 @@ 1, ); - /** - * Unary elements. - * HTML5 section 8.3: - * If current node is an - * area, base, basefont, bgsound, br, col, command, embed, frame, hr, img, - * input, keygen, link, meta, param, source, track or wbr element, then - * continue on to the next child node at this point. - */ - static $unary_elements = array( - 'area' => 1, - 'base' => 1, - 'basefont' => 1, - 'bgsound' => 1, - 'br' => 1, - 'col' => 1, - 'command' => 1, - 'embed' => 1, - 'frame' => 1, - 'hr' => 1, - 'img' => 1, - ); - /** Namespaces that should be treated as "local" to HTML5. */ static $local_ns = array( 'http://www.w3.org/1999/xhtml' => 'html', @@ -199,7 +179,7 @@ class Traverser { } // If not unary, add a closing tag. - if (!$this->isUnary($name)) { + if (Elements::isA($name, Elements::UNARY_TAG)) { $this->closeTag($ele); if ($block) $this->nl(); } @@ -290,19 +270,6 @@ class Traverser { return $ret; } - /** - * Is an unary tag. - * - * @param string $name - * The name of the element to test. - * - * @return bool - * True if Unary and false otherwise. - */ - protected function isUnary($name) { - return isset(self::$unary_elements[$name]); - } - /** * Is block element. * -- cgit v1.2.3 From ddca26307a6aae80aeaf52c7e77e2425fd10054c Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Mon, 29 Apr 2013 15:50:36 -0500 Subject: I feel dirty. Added frameset tag. --- src/HTML5/Elements.php | 1 + 1 file changed, 1 insertion(+) (limited to 'src/HTML5') diff --git a/src/HTML5/Elements.php b/src/HTML5/Elements.php index 429dbbf..ded371d 100644 --- a/src/HTML5/Elements.php +++ b/src/HTML5/Elements.php @@ -148,6 +148,7 @@ class Elements { 'bgsound' => 8, // UNARY_TAG 'noframes' => 2, // RAW_TEXT 'frame' => 9, // NORMAL | UNARY_TAG + 'frameset' => 1, 'center' => 16, 'dir' => 16, 'listing' => 16, // AUTOCLOSE_P 'plaintext' => 48, // AUTOCLOSE_P | TEXT_PLAINTEXT 'applet' => 0, -- cgit v1.2.3