summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Butcher <[email protected]>2013-05-01 11:23:51 -0500
committerMatt Butcher <[email protected]>2013-05-01 11:23:51 -0500
commitd9e49351a1de560f21d4b8880f9d04fe00c6ff07 (patch)
tree8f6384fc7f3c2a91eba87fedb17875295fe012fd
parent9d8b0733bba28d5e057d896bde34d70b25403143 (diff)
parentddca26307a6aae80aeaf52c7e77e2425fd10054c (diff)
Merge branch 'master' of github.com:technosophos/HTML5-PHP
-rw-r--r--src/HTML5/Elements.php8
-rw-r--r--src/HTML5/Serializer/Traverser.php39
-rw-r--r--test/HTML5/ElementsTest.php15
-rw-r--r--test/HTML5/Serializer/TraverserTest.php20
4 files changed, 23 insertions, 59 deletions
diff --git a/src/HTML5/Elements.php b/src/HTML5/Elements.php
index afa3327..ded371d 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,8 @@ class Elements {
'basefont' => 8, // UNARY_TAG
'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,
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 @@
<?php
namespace HTML5\Serializer;
+use \HTML5\Elements;
+
/**
* Traverser for walking a DOM tree.
*
@@ -49,28 +51,6 @@ class Traverser {
'plaintext' => 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();
}
@@ -291,19 +271,6 @@ class Traverser {
}
/**
- * 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.
*
* @param string $name
diff --git a/test/HTML5/ElementsTest.php b/test/HTML5/ElementsTest.php
index 69d0675..df8d336 100644
--- a/test/HTML5/ElementsTest.php
+++ b/test/HTML5/ElementsTest.php
@@ -337,6 +337,21 @@ class ElementsTest extends TestCase {
$this->assertFalse(Elements::isA('scriptypoo', Elements::KNOWN_ELEMENT));
$this->assertTrue(Elements::isA('script', Elements::TEXT_RAW));
$this->assertFalse(Elements::isA('script', Elements::TEXT_RCDATA));
+
+ $unaryElements = array( 'area', 'base', 'basefont', 'bgsound', 'br', 'col',
+ 'command', 'embed', 'frame', 'hr', 'img',
+ );
+
+ foreach ($unaryElements as $element) {
+ $this->assertTrue(Elements::isA($element, Elements::UNARY_TAG), 'Unary test failed on: ' . $element);
+ }
+
+ $nonUnary = array('span', 'a', 'div');
+ foreach ($nonUnary as $tag) {
+ $this->assertFalse(Elements::isA($tag, Elements::UNARY_TAG), 'Unary test failed on: ' . $tag);
+ }
+
+
}
}
diff --git a/test/HTML5/Serializer/TraverserTest.php b/test/HTML5/Serializer/TraverserTest.php
index 665f318..56fa4e1 100644
--- a/test/HTML5/Serializer/TraverserTest.php
+++ b/test/HTML5/Serializer/TraverserTest.php
@@ -44,24 +44,4 @@ class TraverserTest extends \HTML5\Tests\TestCase {
$this->assertFalse($method->invoke($t, $tag), 'Block test failed on: ' . $tag);
}
}
-
- public function testIsUnary() {
- $elements = array( 'area', 'base', 'basefont', 'bgsound', 'br', 'col',
- 'command', 'embed', 'frame', 'hr', 'img',
- );
-
- // Mocking the required input because there is no checking.
- $t = new Traverser('', '');
- $method = $this->getProtectedMethod('isUnary');
-
- foreach ($elements as $element) {
- $this->assertTrue($method->invoke($t, $element), 'Unary test failed on: ' . $element);
- }
-
- $nonblocks = array('span', 'a', 'div');
- foreach ($nonblocks as $tag) {
- $this->assertFalse($method->invoke($t, $tag), 'Unary test failed on: ' . $tag);
- }
- }
-
} \ No newline at end of file