Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Built-in Parameter to Automatically Preserve Attributes #61

Open
playinteractive opened this issue Jul 23, 2024 · 0 comments

Comments

@playinteractive
Copy link

playinteractive commented Jul 23, 2024

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant