-
-
Notifications
You must be signed in to change notification settings - Fork 320
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
html_to_vdom
transform to remove html/body but preserve head content
#832
html_to_vdom
transform to remove html/body but preserve head content
#832
Conversation
Could this be implemented as a transform instead? I suppose one could imagine using the VDOM data structures as a way to create normal HTML templates rather than injecting it into the page in the way IDOM does. Thus, retaining the head and body elements could be useful in that case. |
I don't actually believe there's any use case for people templating HTML/Body/head tags within IDOM. Using scripts outside of the And the If we want to support |
I don't think we should bake this into |
Given that helmet exists, I'm okay with that. On a different note, is there truly a purpose for us to keep the |
We could, though there's not much cost to having them there either aside from the extra |
It has been converted to a transform. |
html_to_vdom
transform to remove html/body but preserve head content
Let me know if deleting |
I didn't have it set to VdomDict because mypy didn't like that for some reason. Was easier to set as a generic dict than figure it out at the time. If we wanna go back to VdomDict we'll need to fix that. |
This reverts commit d78afdb.
I reverted the Let me know if you're comfortable with that. |
Could this transform be more simply written as? def del_html_body_transform(vdom: VdomDict) -> VdomDict:
"""Removes ``<html>``, ``<head>``, and ``<body>`` elements.
This is accomplished by turning the aforementioned elements into fragments.
See :func:`idom.html._` for more details on element fragments.
.. note::
Intended for use with :func:`html_to_vdom`.
Parameters:
vdom:
The VDOM dictionary to transform.
"""
return {**vdom, "tagName": ""} if vdom["tagName"] in {"html", "body", "head"} else vdom |
Yeah. Results in an uglier final VDOM with a bunch of fragments, but functionally would work the same when rendered. |
There's currently some awkwardness in converting
django
views to VDOM, due to the fact that the head content is never loaded into the page.For example, CSS/JS that is within
<head>
is simply never added to the page.This PR makes
html_to_vdom
use the same approach browsers use when merging two HTML/body node trees. Namely, the contents of the<head>
and<body>
tags are directly spit out onto the page, while removing those top level tags themselves.Checklist
Please update this checklist as you complete each item:
changelog.rst
has been updated with any significant changes.