Skip to content

Commit 667e450

Browse files
committed
The library now works the same way as DomDocument when loadHTML() is not called.
1 parent 98e40b4 commit 667e450

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/HTML5DOMDocument.php

-4
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,6 @@ private function addBodyElementIfMissing(): bool
288288
*/
289289
public function saveHTML(\DOMNode $node = null): string
290290
{
291-
if (!$this->loaded) {
292-
return '<!DOCTYPE html>';
293-
}
294-
295291
$nodeMode = $node !== null;
296292
if ($nodeMode && $node instanceof \DOMDocument) {
297293
$nodeMode = false;

tests/Test.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testSaveHTML()
4242

4343
$dom = new HTML5DOMDocument();
4444
// without loading anything
45-
$this->assertTrue('<!DOCTYPE html>' === $dom->saveHTML());
45+
$this->assertTrue('' === $dom->saveHTML());
4646
}
4747

4848
/**
@@ -1465,4 +1465,15 @@ public function testInternalEntityFromGetters(string $dom, string $expectedFromP
14651465
static::assertEquals($expectedFromGetter, $node->getTextContent());
14661466
}
14671467
}
1468+
1469+
/**
1470+
*
1471+
*/
1472+
public function testSaveHTMLWithoutLoadHTML()
1473+
{
1474+
$dom = new \IvoPetkov\HTML5DOMDocument();
1475+
$dom->appendChild($dom->createElement('div'));
1476+
$dom->querySelector('*')->innerHTML = 'text';
1477+
$this->assertEquals('<div>text</div>', $dom->saveHTML());
1478+
}
14681479
}

0 commit comments

Comments
 (0)