@@ -3078,21 +3078,12 @@ private function appendToRealParent($node) {
3078
3078
node, it must instead be inserted into the foster parent element. */
3079
3079
if (!$ this ->foster_parent || !in_array (end ($ this ->stack )->tagName ,
3080
3080
array ('table ' , 'tbody ' , 'tfoot ' , 'thead ' , 'tr ' ))) {
3081
- $ this -> appendChild ( end ($ this ->stack ), $ node );
3081
+ end ($ this ->stack )-> appendChild ( $ node );
3082
3082
} else {
3083
3083
$ this ->fosterParent ($ node );
3084
3084
}
3085
3085
}
3086
3086
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
-
3096
3087
private function insertBefore ($ parent , $ node , $ marker ) {
3097
3088
if ($ node instanceof DOMText) {
3098
3089
if ($ marker instanceof DOMText) {
@@ -3500,7 +3491,7 @@ public function fosterParent($node) {
3500
3491
if ($ table ->tagName === 'table ' && $ table ->parentNode ->isSameNode ($ foster_parent )) {
3501
3492
$ this ->insertBefore ($ foster_parent , $ node , $ table );
3502
3493
} else {
3503
- $ this ->appendChild ($ foster_parent , $ node );
3494
+ $ foster_parent ->appendChild ($ node );
3504
3495
}
3505
3496
}
3506
3497
@@ -3721,6 +3712,7 @@ public function insertForeignElement($token, $namespaceURI) {
3721
3712
}
3722
3713
3723
3714
public function save () {
3715
+ $ this ->dom ->normalize ();
3724
3716
if (!$ this ->fragment ) {
3725
3717
return $ this ->dom ;
3726
3718
} else {
0 commit comments