Knio / dominate

Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API. It allows you to write HTML pages in pure Python very concisely, which eliminate the need to learn another template language, and to take advantage of the more powerful features of Python.
GNU Lesser General Public License v3.0
1.71k stars 110 forks source link

unexpected context behaviour #173

Closed bitplorer closed 1 year ago

bitplorer commented 1 year ago

Here is a minimal code

def subcontext(*args):
    with div("sub context") as _subcontext:
        _subcontext.add(*args)
    return  _subcontext

with div("context") as context_1:
    subcontext(div("inside subcontext"))

with div("context") as context_2:
    inside_context_and_hello = div("inside context and subcontext")
    subcontext(inside_context_and_hello)

print(context_1)
print(context_2)

expected context_1 output :

<div>
  context
  <div>
    sub context
    <div>
      inside subcontext
    </div>
  </div>
</div>

actual context_1 output:

<div>
  context
  <div>
    inside subcontext
  </div>
  <div>
    sub context
    <div>
      inside subcontext
    </div>
  </div>
</div>

while context_2 actual output is same as expected:

<div>
  context
  <div>
    inside context and subcontext
  </div>
  <div>
    sub context
    <div>
      inside context and subcontext
    </div>
  </div>
</div>

how should context behaviour be changed ?

Knio commented 1 year ago

that does seem weird. what is _hello on line 4?

Knio commented 1 year ago

case 1 is fixed. case 2 i do not believe should have different behaviour than case 1. if you want a node to be added twice, it should be explicit with .add() in both places

bitplorer commented 1 year ago

Thanks !

Knio commented 1 year ago

published 2.8.0