Skip to content

Commit f428154

Browse files
committed
Remove TreeConstructer::appendChild() and just call DOMNode::normalize() when saving (this has identical behaviour).
1 parent 1db1716 commit f428154

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

library/HTML5/TreeConstructer.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,21 +3078,12 @@ private function appendToRealParent($node) {
30783078
node, it must instead be inserted into the foster parent element. */
30793079
if(!$this->foster_parent || !in_array(end($this->stack)->tagName,
30803080
array('table', 'tbody', 'tfoot', 'thead', 'tr'))) {
3081-
$this->appendChild(end($this->stack), $node);
3081+
end($this->stack)->appendChild($node);
30823082
} else {
30833083
$this->fosterParent($node);
30843084
}
30853085
}
30863086

3087-
private function appendChild($parent, $node) {
3088-
if ($node instanceof DOMText && $parent->lastChild instanceof DOMText) {
3089-
// attach text to previous node
3090-
$parent->lastChild->data .= $node->data;
3091-
} else {
3092-
$parent->appendChild($node);
3093-
}
3094-
}
3095-
30963087
private function insertBefore($parent, $node, $marker) {
30973088
if ($node instanceof DOMText) {
30983089
if ($marker instanceof DOMText) {
@@ -3500,7 +3491,7 @@ public function fosterParent($node) {
35003491
if ($table->tagName === 'table' && $table->parentNode->isSameNode($foster_parent)) {
35013492
$this->insertBefore($foster_parent, $node, $table);
35023493
} else {
3503-
$this->appendChild($foster_parent, $node);
3494+
$foster_parent->appendChild($node);
35043495
}
35053496
}
35063497

@@ -3721,6 +3712,7 @@ public function insertForeignElement($token, $namespaceURI) {
37213712
}
37223713

37233714
public function save() {
3715+
$this->dom->normalize();
37243716
if (!$this->fragment) {
37253717
return $this->dom;
37263718
} else {

0 commit comments

Comments
 (0)