@@ 257-279 (lines=23) @@ | ||
254 | $this->node = $newNode; |
|
255 | ||
256 | // Remove head element, preserving child nodes. (again) |
|
257 | if ( |
|
258 | $this->node->parentNode instanceof \DOMElement |
|
259 | && |
|
260 | $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper() |
|
261 | ) { |
|
262 | $html = $this->node->parentNode->getElementsByTagName('head')[0]; |
|
263 | ||
264 | if ($this->node->parentNode->ownerDocument !== null) { |
|
265 | $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment(); |
|
266 | if ($html !== null) { |
|
267 | /** @var \DOMNode $html */ |
|
268 | while ($html->childNodes->length > 0) { |
|
269 | $tmpNode = $html->childNodes->item(0); |
|
270 | if ($tmpNode !== null) { |
|
271 | /** @noinspection UnusedFunctionResultInspection */ |
|
272 | $fragment->appendChild($tmpNode); |
|
273 | } |
|
274 | } |
|
275 | /** @noinspection UnusedFunctionResultInspection */ |
|
276 | $html->parentNode->replaceChild($fragment, $html); |
|
277 | } |
|
278 | } |
|
279 | } |
|
280 | ||
281 | return $this; |
|
282 | } |
|
@@ 820-844 (lines=25) @@ | ||
817 | } |
|
818 | ||
819 | // Remove head element, preserving child nodes. |
|
820 | if ( |
|
821 | $removeExtraHeadTag |
|
822 | && |
|
823 | $this->node->parentNode instanceof \DOMElement |
|
824 | && |
|
825 | $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper() |
|
826 | ) { |
|
827 | $html = $this->node->parentNode->getElementsByTagName('head')[0] ?? null; |
|
828 | ||
829 | if ($html !== null && $this->node->parentNode->ownerDocument !== null) { |
|
830 | $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment(); |
|
831 | ||
832 | /** @var \DOMNode $html */ |
|
833 | while ($html->childNodes->length > 0) { |
|
834 | $tmpNode = $html->childNodes->item(0); |
|
835 | if ($tmpNode !== null) { |
|
836 | /** @noinspection UnusedFunctionResultInspection */ |
|
837 | $fragment->appendChild($tmpNode); |
|
838 | } |
|
839 | } |
|
840 | ||
841 | /** @noinspection UnusedFunctionResultInspection */ |
|
842 | $html->parentNode->replaceChild($fragment, $html); |
|
843 | } |
|
844 | } |
|
845 | ||
846 | return $newDocument; |
|
847 | } |