Skip to content

Commit 24257c8

Browse files
committed
Alternative implementation of #115
1 parent 4c3a923 commit 24257c8

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

src/HTML5/Serializer/OutputRules.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ public function element($ele)
223223
foreach ($ele->childNodes as $child) {
224224
if ($child instanceof \DOMCharacterData) {
225225
$this->wr($child->data);
226+
} elseif ($child instanceof \DOMElement) {
227+
$this->element($child);
226228
}
227229
}
228230
} else {

test/HTML5/Serializer/OutputRulesTest.php

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -627,34 +627,24 @@ public function testHandlingInvalidRawContent()
627627
{
628628
$dom = $this->html5->loadHTML(
629629
'<!doctype html>
630-
<html lang="en" id="base">
631-
<body>
632-
<p>Foo</p>
633-
<style id="test">
634-
blah
635-
</style>
636-
<p>Baz</p>
637-
</body>
638-
</html>');
639-
640-
// modify the content of the TEXT_RAW element
641-
$badNode = $dom->createElement("p");
642-
$badNode->appendChild($dom->createTextNode("Bar"));
643-
644-
$styleElement = $dom->getElementById("test");
630+
<html lang="en" id="base">
631+
<body>
632+
<script id="template" type="x-tmpl-mustache">
633+
<h1>Hello!</h1>
634+
</script>
635+
</body>
636+
</html>');
637+
638+
$badNode = $dom->createElement("p", "Bar");
639+
640+
// modify the content of the TEXT_RAW element: <script id="template"> appending dom nodes
641+
$styleElement = $dom->getElementById("template");
645642
$styleElement->appendChild($badNode);
646643

647-
// create the OutputRules instance and run the tests
648-
$stream = fopen('php://temp', 'w');
649-
$r = new OutputRules($stream, $this->html5->getOptions());
650-
$t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
651-
652-
$r->element($dom->getElementById('base'));
653-
$contents = stream_get_contents($stream, - 1, 0);
654-
655-
$this->assertRegExp('|<p>Foo</p>|', $contents);
656-
$this->assertNotRegExp('|<p>Bar</p>|', $contents);
657-
$this->assertRegExp('|<p>Baz</p>|', $contents);
644+
$contents = $this->html5->saveHTML($dom);
658645

646+
$this->assertTrue(strpos($contents, '<script id="template" type="x-tmpl-mustache">
647+
<h1>Hello!</h1>
648+
<p>Bar</p></script>')!==false);
659649
}
660650
}

0 commit comments

Comments
 (0)