-
-
Notifications
You must be signed in to change notification settings - Fork 42
Description
Hi,
I would like to suggest a feature enhancement for the library. When using the insertHTML method, it would be incredibly useful to have a built-in parameter that automatically preserves attributes from the original document.
Currently, when insertHTML is used, attributes such as lang on the tag are overwritten by the new HTML content. This can lead to issues where important document settings are unintentionally lost. For example, consider the following scenario:
$dom = new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('<!DOCTYPE html><html lang="en"><body><h1>Hello</h1><div class="content">This is some text</div></body></html>', IvoPetkov\HTML5DOMDocument::ALLOW_DUPLICATE_IDS);
$dom->insertHTML('<!DOCTYPE html><html lang="ca"><body><h1>Hello</h1><div class="content">Another text</div></body></html>');
echo $dom->saveHTML();
In this case, the lang attribute is changed from "en" to "ca", which might not be the desired outcome. To handle this, a typical workaround involves manually saving and restoring the attributes, which adds complexity to the code.
I propose adding an option to insertHTML that preserves the existing attributes from the original document, making it easier for users to maintain document settings without additional manual steps.
Cheers,