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: HTML5DOMDocumentFragment with appendHTML() #57

Open
rulatir opened this issue Jan 2, 2023 · 5 comments
Open

Feature request: HTML5DOMDocumentFragment with appendHTML() #57

rulatir opened this issue Jan 2, 2023 · 5 comments

Comments

@rulatir
Copy link

rulatir commented Jan 2, 2023

Since XML is not HTML, using native DOMDocumentFragment and its appendXML() method is risky and prone to all the very same issues this library is trying to address.

@ivopetkov
Copy link
Owner

There are already two methods to help you with this. Please take a look at HTML5DOMDocument::insertHTML() and HTML5DOMDocument::insertHTMLMulti(). There is an example at https://github.com/ivopetkov/html5-dom-document-php (in the README section).

@rulatir
Copy link
Author

rulatir commented Jan 3, 2023

I am implementing a contract that requires me to return a DOMDocumentFragment.

@ivopetkov
Copy link
Owner

Would you provide some example code so I can better understand the problem you're trying to solve and the API you're requesting?

@rulatir
Copy link
Author

rulatir commented Jan 12, 2023

I must return a DOMDocumentFragment, because that is what a contract enforced by a 3rd-party library requires of me. I must also be able to assemble the contents of the resulting DOMDocumentFragment from pieces, which can be:

  • DOMNodes, including other DOMDocumentFragments,
  • strings of raw HTML

YES, I can do this:

  • for each $piece
    • if $piece is a DOMNode, just append it to the fragment
    • else
      • create a temporary HTML5DOMDocument
      • load a HTML skeleton containing <div id="processing-container">$piece</div> into the document
      • iterate over the children of the processing container, clone them, and append them to the DOMDocumentFragment

But that is a huge amount of work for what should be much easier to do, and with the requested feature, it would be. If the purpose of this library is to make HTML manipulation easy, then this feature is missing.

@ivopetkov
Copy link
Owner

Currently, I do not have plans to add fragments support. Maybe someday. Feel free to contribute such code to the library.

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

2 participants