diff options
-rw-r--r-- | src/HTML5/Elements.php | 13 | ||||
-rw-r--r-- | test/HTML5/Parser/TokenizerTest.php | 26 |
2 files changed, 23 insertions, 16 deletions
diff --git a/src/HTML5/Elements.php b/src/HTML5/Elements.php index 99cd6a3..51784a7 100644 --- a/src/HTML5/Elements.php +++ b/src/HTML5/Elements.php @@ -11,8 +11,15 @@ namespace HTML5; class Elements { const KNOWN_ELEMENT = 1; + + // From section 8.1.2: "script", "style" + // From 8.2.5.4.7 ("in body" insertion mode): "noembed", "noscript" + // From 8.4 "style", "xmp", "iframe", "noembed", "noframes" const TEXT_RAW = 2; + + // From section 8.1.2: "textarea", "title" const TEXT_RCDATA = 4; + const VOID_TAG = 8; // "address", "article", "aside", "blockquote", "center", "details", "dialog", "dir", "div", "dl", @@ -110,7 +117,7 @@ class Elements { "output" => 65, // NORMAL | BLOCK_TAG "p" => 81, // NORMAL | AUTOCLOSE_P | BLOCK_TAG "param" => 9, // NORMAL | VOID_TAG - "pre" => 83, // NORMAL | TEXT_RAW | AUTOCLOSE_P | BLOCK_TAG + "pre" => 81, // NORMAL | AUTOCLOSE_P | BLOCK_TAG "progress" => 1, "q" => 1, "rp" => 1, @@ -157,7 +164,7 @@ class Elements { 'applet' => 0, 'marquee' => 0, 'isindex' => 8, // VOID_TAG - 'xmp' => 18, // AUTOCLOSE_P | VOID_TAG + 'xmp' => 20, // AUTOCLOSE_P | VOID_TAG | RAW_TEXT 'noembed' => 2, // RAW_TEXT ); @@ -289,7 +296,7 @@ class Elements { "polyline" => 1, "radialGradient" => 1, "rect" => 1, - "script" => 1, + "script" => 3, // NORMAL | RAW_TEXT "set" => 1, "stop" => 1, "style" => 3, // NORMAL | RAW_TEXT diff --git a/test/HTML5/Parser/TokenizerTest.php b/test/HTML5/Parser/TokenizerTest.php index 7ec4c76..10f9f9a 100644 --- a/test/HTML5/Parser/TokenizerTest.php +++ b/test/HTML5/Parser/TokenizerTest.php @@ -389,30 +389,30 @@ class TokenizerTest extends \HTML5\Tests\TestCase { public function testRawText() { $good = array( - '<pre>abcd efg hijk lmnop</pre> ' => 'abcd efg hijk lmnop', - '<pre><not/><the/><tag></pre>' => '<not/><the/><tag>', - '<pre><<<<<<<<</pre>' => '<<<<<<<<', - '<pre>hello</pre</pre>' => 'hello</pre', - "<pre>\nhello</pre\n</pre>" => "\nhello</pre\n", - '<pre>&</pre>' => '&', - '<pre><!--not a comment--></pre>' => '<!--not a comment-->', - '<pre><![CDATA[not a comment]]></pre>' => '<![CDATA[not a comment]]>', + '<script>abcd efg hijk lmnop</script> ' => 'abcd efg hijk lmnop', + '<script><not/><the/><tag></script>' => '<not/><the/><tag>', + '<script><<<<<<<<</script>' => '<<<<<<<<', + '<script>hello</script</script>' => 'hello</script', + "<script>\nhello</script\n</script>" => "\nhello</script\n", + '<script>&</script>' => '&', + '<script><!--not a comment--></script>' => '<!--not a comment-->', + '<script><![CDATA[not a comment]]></script>' => '<![CDATA[not a comment]]>', ); foreach ($good as $test => $expects) { $events = $this->parse($test); - $this->assertEventEquals('startTag', 'pre', $events->get(0)); + $this->assertEventEquals('startTag', 'script', $events->get(0)); $this->assertEventEquals('text', $expects, $events->get(1)); - $this->assertEventEquals('endTag', 'pre', $events->get(2)); + $this->assertEventEquals('endTag', 'script', $events->get(2)); } $bad = array( - '<pre>&</pre' => '&</pre', - '<pre>Hello world' => 'Hello world', + '<script>&</script' => '&</script', + '<script>Hello world' => 'Hello world', ); foreach ($bad as $test => $expects) { $events = $this->parse($test); $this->assertEquals(4, $events->depth(), "Counting events for '$test': " . print_r($events, TRUE)); - $this->assertEventEquals('startTag', 'pre', $events->get(0)); + $this->assertEventEquals('startTag', 'script', $events->get(0)); $this->assertEventError($events->get(1)); $this->assertEventEquals('text', $expects, $events->get(2)); } |