Comments (4)
No issue/problem/question stated and this looks working as intended
from dominate.
@Knio
The tag represents the root of an HTML document. (from https://www.w3schools.com/tags/tag_html.asp)
so - i dont think it should nest, which is what is happening if you look at the output from the second occurence of
instead, I think a better design choice is, when a html root is entered/exited, it does not register itself as a child of what is on the context, breaking the chain.
roughly what happend is that
with dominate.document() as xxx: ...
should has no other effect then writing xxx.
This come up in real life, when I try to use dominate, as I try to create multiple webpage in a hirearchical order. I initially wrote a recursive function to do that, starting from the main entry, generating hyperlink on needed, but as dominate doesnt support that I have to rewrite it from a top-down to a bottom-up manner.
from dominate.
i dont think it should nest
This project is not meant to be an html validator - i.e. it doesn't check that <td>
is inside a <tr>
, or that some tag has all the required attributes set, etc. and I don't want to special case any nodes. Also, I think nesting is legal (ok maybe only in an <embed>
but I'm not going to check the whole spec)
with dominate.document() as xxx: ...
should has no other effect then writing xxx.
This is explicitly asking for it to be the context. Not doing so would break the expectations of the API. If you don't want the effect, why not just write xxx = dominate.document()
?
If xxx = ...
is still inside some outer context and causing problems:
but as dominate doesnt support that I have to rewrite it from a top-down to a bottom-up manner.
That seems like an excessive reaction, why don't you just subclass document
to do what you want?
class mydoc(dominate.document):
def _add_to_ctx(self): pass # don't add to contexts
With your example do what I think you want:
>>> with mydoc() as outer_doc:
... with mydoc() as inner_doc:
... p('meow')
... print(inner_doc)
...
<dominate.tags.p at 1bb1a765160: 0 attributes, 1 child>
<!DOCTYPE html>
<html>
<head>
<title>Dominate</title>
</head>
<body>
<p>meow</p>
</body>
</html>
>>> print(outer_doc)
<!DOCTYPE html>
<html>
<head>
<title>Dominate</title>
</head>
<body></body>
</html>
from dominate.
Thx. the subclass solution is excatly what I want.
from dominate.
Related Issues (20)
- Some HTML5 tags are missing
- Custom elements HOT 1
- Prevent escaping of attributes?
- Repeatedly calling attr() on same attribute doesn't accumulate values HOT 1
- tag(attr=None) renders as <tag attr="None"></tag>
- pip usage HOT 1
- Release Notes HOT 1
- Enable attributes without values HOT 2
- Treat None as an empty string?
- Add hyper link within a string of text
- Replace deprecated imp module with importlib HOT 2
- unexpected context behaviour HOT 4
- tests/test_dom_tag.py:20: AssertionError while building for i686 HOT 4
- the title is wrong标题乱码 HOT 3
- Planning to add HTMX support? HOT 1
- Support Python 3.12, `No module named 'imp'` HOT 2
- Dominate doesn't work with async code (+ potential fix) HOT 3
- ModuleNotFoundError: No module named 'contextvars'
- Missing contextvars dependency HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dominate.